tags:

views:

648

answers:

6

I am very interested in c++ and want to master this language. I have read a lot of books about c++. I want to read some library source code to improve my skill, but when I read the boost library source code, I find it is very difficulty.
Can anyone give me some advice about how to read boost source code and before I can understand it what kind of books about c++ should I read?

+11  A: 

If you're starting out in C++, the boost source code is probably not the best place. It's where the wizards hang out and they deal in template magic. I think a better starting point are Scott Myers and Herb Sutters books (in that order).

Some versions of Scott's book can be a bit out dated but they are still strong in the fundamentals. Herb's books are worth reading many many times and are an invaluable tool. Once you've gotten through both of those authors, then would be a good time to tackle the boost source code.

JaredPar
Are you following me around ;)
OJ
@OJ, you're just not moving fast enough ;)
JaredPar
It's fun to watch. You guys must have similar favorite'd tags.
Ape-inago
yeah, thank you for advice, I have read "c++ primer", "exceptional c++", "effective c++","Inside the c++ object model" and "c++ common knowledge". In my code, template, metaprogramming is not used, so I read boost library code to improve my knowledge in that area.
cppguy
+1 for that response. Made me LOL.
OJ
Add "More Effective C++" to that list. Another Meyer classic. But start writing code.
OJ
cppguy said: "In my code, template, metaprogramming is not used, so I read boost library code to improve my knowledge in that area". That's funny: I use the same argument to NOT improve my knowledge in that area...
Roddy
+9  A: 

I can't give advice on how to read boost code, but I can offer some other advice.

Stop reading and start writing :) Reading is valuable, but you won't learn anywhere near as much unless you start writing code yourself. Start with the basics. Read the beginners books and type out the samples (don't copy and paste). You'll learn by having to fix the errors that are the result of you mistyping. Play with some of your own ideas for simple applications and go from there.

Starting off by reading boost source code is a sure fire way of scaring yourself off the language and/or ending up very confused with a lot of questions.

Start small, work your way up.

OJ
Yes, if you are interested in boost, start actually using it - once you can use, you can also look behind the scenes and you will have a better understanding of how things are hanging together
none
+1  A: 

Yeah, there is some truly awful stuff in some of the boost libraries. If you want to read some very nice source code, try checking out WebKit or some of the Google open source projects (like Chrome or Protobufs).

jeffamaphone
yeah, google open source code seems a little nice, and I read some part of its "ctemplate" code
cppguy
Yeah, the thing is with companies like Apple and Google, their open source code is actually code reviewed, and style rules and best-practices for coding are actually enforced. And there is typically someone very experienced and brilliant guiding the project. The only non-corporate open source project I've seen that even comes close to that kind of consistency is the SVN project, but its straight C, not C++.
jeffamaphone
+6  A: 

I imagine boost uses a lot of advanced c++ features like templating etc. Boost libraries tend to be very complicated as they try to follow strict programming standards and styles for them to be compatible with things like the STL.

Quite simply, if you don't understand it, you are probably in over your head. and if you do understand it, you don't really need to be reading it anyway. Don't jump into the water if you don't know how to swim... You've essentially tried to swim up a waterfall.

Ape-inago
also, there are lots of cross-platform issues being addressed internally by boost, which adds another layer of complexity
none
A: 

Id suggest you start off with something like Lipmann's Premiere(other begginers books of your liking). Then, when you're comfortable with the code, you can move on to Herb Sutter, Alexandresku to broaden your horizons, acquire a more complete view on the soft dev. And MOST IMPORTANTLY - to be able to cede well one has to code A LOT, as it is a skill just as any other and it takes practice to master.

P.S.> If you're confident you can pick up Stroustrup right from the start along with other book(s). I don't think that theres another source on C++ just as complete as the authors.

+5  A: 

Since you mention that you want to learn the dark art of meta programming then I would recommend "Modern C++ Design" by Andrei Alexandrescu.

Meta programming is a very complicated area and is not required most of the time. Once you learn about it, it is very easy to think that it can solve all your problems. It becomes your new favourite hammer.

I would also recommend becoming a very proficient user of libraries based on meta programming like boost and loki before you add it to your own code.

Two different programmers used meta programming in parts of the code base I am responsible for. While they were skilled programmers a commercial product should not be treated like a playground. These are probably the worst area's of our code base now, very complicated and very brittle esp when you add support for new compilers. If I was responsible for the code when they were written they would not be here, now they are too expensive to replace.

In short you very rarely need meta programming unless you are a library writer. And you cannot be a library writer without being a very accomplished library user.

iain
yeah, your answer helps me a lot, thank you
cppguy