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?
views:
648answers:
6If 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.
- Scott Myers: Effective C++
- Scott Myers: Effective STL
- Herb Sutter - Really I would go for anything with Effective and C++ in the title from this list.
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.
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).
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.
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.
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.