Re: The way to read STL source code
On Friday, February 17, 2012 9:15:55 PM UTC+8, Nick Keighley wrote:
On Feb 17, 11:57 am, Goran <goran.pu...@gmail.com> wrote:
On Feb 17, 10:12 am, Nick Keighley <nick_keighley_nos...@hotmail.com>
On Feb 17, 7:36 am, Goran <goran.pu...@gmail.com> wrote:
On Feb 17, 8:18 am, Stanley Rice <hecong...@gmail.com> wrote:
I am familiar with using STL, including the algorithm and the
containers, however, how they are implemented. Some of my friends
recommend me to read the source code of STL directly.
Reading is too dry.
nonsense!
I misunderstood here. Since I think reading the STL code is so
obviously mad I assumed you were saying "reading a book was too dry".
But I see not. If I want to know what the STL does I read Jossutis. or
use an online source.
Try debugging through it.
yuck!
Start with the simplest
of things, like for_each, vector::push_back, list::push_front. Just
make simplest of programs, e.g.
int main()
{
std::vector<char> v;
v.push_back('a');
}
and go through with the debugger.
In the beginning, it will be difficult, because you will need to le=
arn
to see through the cruft that's inside. Typically, you'll see a lot=
of
code whose sole purpose is to aid debugging. You'll need to learn t=
o
ignore that. You will also see bizarre variable naming. Live with i=
t.
Variable naming in STL is subject to different considerations than
your or mine code ;-).
or you could try poking your own eyes out
it just seems a lot of pain ...cruft...bizzare variable naming... for
very little gain.
I find that watching code unroll in the debugger is a great way of
learning what code does.
I'm less enthusiastic. Very unenthusiastic in fact. And it doesn't
help you learn what the STL /should/ be doing. Without reading some
sort of documentation I don't see how you'd even know certain features
existed.
Even more so when it's about usual STL
implementations code.
even less is my thought. The STL is particularly ugly lookign code.
Why do you care how it's implemented? Do you single shot through the C
libraries? You probably do I suppose...
Another reason that I want to read the source code is that I want to improv=
e my understanding of data structure and algorithm in the same time. STL co=
vers nearly all the basic data structure and algorithms.
I don't get your excitement.
what excitement?
It's not very elaborate either ;-).
the STL? It's pretty subtle.