views:

1666

answers:

8

What C++ open-source projects have good and clean code? I would like to go through it and learn the design and implementation tricks used there.

There was a similar question about C code here, but I would be specifically interested in C++ projects, especially in ones that use modern programming approaches and have modular but not bloated overall structure and object-oriented design.

I know I could look at code in Project Euler or Topcoder, but I'd like to see the architecture and design of a whole nicely-sized, but not too large project (say, up to 50 or so classes).

There was also this question, but no one mentioned C++ projects.

And one more thing: I know the best way to learn is actually writing code yourself. But I'm already doing that. A lot.

+2  A: 

The Boost C++ libraries are very good examples of good modern C++ design.

Ben Collins
But rather abstract and full of platform-specific quirks and hence difficult to understand in many places. A more concrete example might be more helpful.
MarkR
@MarkR: That criticism doesn't make any sense. Not every library in Boost is implemented in a very abstract problem space, and many of the libraries are 100% portable and don't touch the underlying platform at all.
Ben Collins
I'd also suggest that you lurk on boost mailing list. There are a lot of good discussions on good and clean design/code.
obecalp
Please don't look at Boost *first*. Or if you do, stick to the non-metaprogramming parts like Filesystem or Thread. As a rule, the more generic code is, the less readable it is, and Boost is for the most part *very* generic.
j_random_hacker
+3  A: 

Trolltech's Qt library has a great design.

Another good way is to learn good design is to read a book on design patterns, such as this one.

Brian R. Bondy
A: 

IMHO, DC++ (a client for the Direct Connect protocol) is quite well done, makes use of C++'s features in all the right ways and has a manageable size. I always liked poking around in its source.

sth
+4  A: 

I've learned from the code of Binutils Gold and i liked the clean style of the LLVM source-code.

You can also have a look into the boost code. It's probably not easy to understand because their writers know a lot of C++ and assume its readers know too. But of course its code is the lingua franca of C++.

Johannes Schaub - litb
A: 

I would like to read some good C++ books instead of study these codes. I think for every project, they have different background, design and implementation, most of them didn't provide a good document.

Yigang Wu
Books are fine for some things, but it's also useful to "look under the hood" of a real working project to see how it deals with the project organization and so on. Plus, the guy asked about that, not books. ;)
Nik Reiman
+2  A: 

I've always admired the OpenSceneGraph for a really clean, modern approach to C++. It's a larger code base but very modular, so you don't need to chew off too much at a time :)

Not a lot of comments though, so be prepared to actually read some code.

Gian Paolo
+1  A: 

I recommend looking at ACE for examples of good C++ code and design principles.

jcrossley3
+1  A: 

A great example of a large system in C++ is Chrome. The C++ is fairly nice, and it's interesting to see how they tackled the challenge of organizing such a large system.

Ben Straub
Ha, I didn't know it's open source!