I'm trying to improve my c++ coding technique by reading c++ source code. Which open source project would you recommend? Is the code of Boost C++ Libraries a good one?
I would recommend any of Google's open source C++ code, such as the following:
Advantages of using Google code:
- It's written to high standards and is peer reviewed (unlike some open source code).
- It has good developer documentation (which makes it easier to pick up and understand).
- It uses some moderately advanced C++ techniques (and thus is good for learning).
- It's probably easier to understand than Boost because it doesn't rely so much on advanced template metaprogramming and preprocessor metaprogramming and isn't weighed down as much with countless compiler compatibility hacks and special cases.
The Google C++ Style Guide that Google's C++ code uses is generally good, but it does have some fairly unusual bits (such as some of their naming guidelines or their disallowing exceptions), so keep in mind that their C++ code will differ in those respects from what you'll see in the field.
I wouldn't recommend reading a code base. I'd recommend reading C++ FAQS. There's also an excellent book that goes along with the site. Best way to improve your C++ coding skills.
Reading existing clean C++ code is a great way to learn the language.
The code in the OpenFST toolkit is very clean, for example. It is readable and uses slightly advanced features without going overboard.
Boost, on the other hand, can be a bit hard to read, partly because they use C++ tricks that are hard to understand and because they often sprinkle the code with different workarounds for different compiler versions.
I would suggest reading the "Effective C++" by Scott Meyers and using the suggestions he has in little toy programs.
Try reading something that has been existing for years and is large in size. It will take a few months of time to start to understand the code and getting to do something in it.
Firefox, Thunderbird, OpenOffice.org, LibreOffice come to the mind. There should be many more similar ones too. These projects run on many operating systems and hardware platforms. Also, they have to score on readability. These could should you the techniques you look for.
Even better than reading the code would be to work with that code in form of fixing bugs and adding small improvements here and there. Pick some program, preferably one you have use for, sign up to the mailing list, start going through their bug tracker and try to diagnose some bugs. Ask on the mailing list if you find solution for something whether it's reasonable or when you get stuck. That will give you some specific goals when reading the code, force you to really understand and is what you'll be doing most of the time in any work.
You can perhaps look at some KDE application. Most are written in C++ and you can start with some smaller one first.
Yes, the code of Boost C++ Libraries is a great resource to learn from, if not one of the best on the Planet. However, for a novice, learning from Boost code may make learning curve very steep. If you really want to try reading Boost, start with some small and simple libraries like Boost.Array.