Jorgen Grahn wrote:
> On Sun, 2012-06-17, Pavel wrote:
>> Jorgen Grahn wrote:
>>> On Sun, 2012-06-17, Pavel wrote:
>>>> Also, IMHO reading an important piece of source code (e.g. that of a modern
>>>> version of C++ Standard Library) can be more instructive than reading a good book.
>>>
>>> You need to do both. Not sure reading the STL is the best thing you
>>> can do though -- general-purpose libraries are very unlike the code
>>> you'll spend most of your time reading and writing.
>
>> Yes, the domain one will work for will probably be different but this does not
>> make this code less instructive. In my experience, the source code of STL in
>> particular is one of the best exposures of non-obvious issues one would face to
>> efficiently implement seemingly straightforward specifications in C++.
>
> I agree reading it is useful. But you don't get this from it: the
> mapping from a concrete typical real-world problem into a (probably
> object-oriented) design, and the mapping of that into C++ code.
Oh, yes, I most certainly agree STL does not provide much insights to
OOA&D-in-C++. Some other Standard C++ Library facilities, like streambuf
hierarchy, do more of it -- but I am far from calling streambuf a good OOA&D
example.
IMO the main benefit from Standard Library code reading is learning the language
features and their application to low-level problems rather than developing
one's design-at-large skills. STL, however, provides an example of good design
as an additional benefit even though it does not use many OO techniques. I have
to admit I don't really know whether STL is technically OO or not: on one hand,
it has classes and achieves main goals of a good OO design, such as loose
coupling and high cohesion; on the other, it does not use virtual functions,
is-a type of inheritance etc. I am not crazy about pigeon-holing so I won't lose
my sleep about this question.
>
> STL *does* solve a real-world problem, but an unusual one: to provide
> efficient general-purpose containers and algorithms which will suit
> almost all needs.
>
> /Jorgen
>
-Pavel
|