Fog Creek Software
g
Discussion Board




Quality source code

I'm looking for C++ source code that I could learn from. What open-source projects have the best quality source code? Are there any projects that I should avoid looking at? So far I have seen several C programs that had what I think was very good quality source, but there's much less C++ out there. I don't care whether they are linux or windows or OSX programs, as long as I can just read the code and learn.

I don't want books, examples or demos - just real working code that actually does something useful.

TomA
Saturday, March 13, 2004

What kind of program are you interested in?  You'll probably be better able to judge the beauty of the code if you understand the subject matter reasonably well.

K
Saturday, March 13, 2004

sweetcode.org

Hit archives and start downloading

--
ee

eclectic_echidna
Saturday, March 13, 2004

LyX (http://www.lyx.org)  has some great C++ code.  However, it also has some abominable stuff that's getting pulled out.

If you want to see some great C++ std::* usage.  LyX is a good bet.

Koz
Saturday, March 13, 2004

I think there's a lot to be learned from FLTK (many others disagree). Among other things, it puts globals to very good use and simplicity for the end user above all else. [ http://fltk.org ].

Boost is good in theory, but I don't like it in practice. YMMV [ http://boost.org ]

Stay away from MFC or ATL.

Ori Berger
Saturday, March 13, 2004

What don't you like about boost?

K
Saturday, March 13, 2004

I like FLTK too. The style is very practical/"real world".

Check out the ILM floating-point image file code at www.openexr.org. (it's not just image processing, there are some support libraries as well). Pretty clean and idiomatic use of C++ with STL.

Dan Maas
Sunday, March 14, 2004

Also KDE (www.kde.org) contains a HUGE amount of C++ code. There are some rough spots, but the core libraries (esp. Qt) are very clean.

Dan Maas
Sunday, March 14, 2004

I learned a lot about OO coding from the source of log4cpp. http://log4cpp.sourceforge.net/

ICBW
Sunday, March 14, 2004

Thanks very much for all the suggestions. KDE and Qt are great.

As for boost, I think I'll come to appreciate it when I learn more about the basics.

Sweetcode is full of ideas, great site.

TomA
Sunday, March 14, 2004

There is also the magnificent ACE Toolkit:
http://www.cs.wustl.edu/~schmidt/ACE.html

gunga
Sunday, March 14, 2004


Pick up a copy of the Windows 2000 source that's going around.  It will teach you what not to do.

Joe on Software (Joe)
Sunday, March 14, 2004

Whenever I look at boost and similar code, my spider sense, (or is that common sense?) triggers with a "wrong tool for the job" message.

Compile times skyrocket (5 minutes on a reasonably equipped machine for a 2000 line file is not unheard of); The source is often unreadable unless you are very familiar with the library in question; Error messages are seldom, if ever, meaningful.

If you want a lexer/parser, lex, yacc and friends (D, Lemon, etc) do a much better job than boost's spirit ever could, whether in the debugging or specification phase.

If you want currying, closures and friends, Lisp does a much better job.

Don't know the state of affairs now, but two years ago, many compilers couldn't compile boost properly - and boost was modified around the compilers' deficiencies.

[Ab]using the turing-completeness property of the C++ template mechanism, and to some extent the C preprocessor is an overkill, in my opinion, and wrong-tool-for-the-job overly complex in my opinion.

P.S: I don't like STL either.

Ori Berger
Sunday, March 14, 2004

The point of spirit is to allow grammars to be directly specified in your source code (ideally to make maintaining a program easier).  My beef about it is just that it's an LL parser, rather than a general LR parser.

The boost project also has some very useful libraries for even more common problems, like parsing regular languages or searching/constructing graphs.

But if you don't like STL, you'll HATE boost.  You've really got to be willing to drink the template kool-aid to get into boost.

K
Monday, March 15, 2004

Holy cow what a good question. I wish people asked this before they wrote PHP and Perl.

Me
Monday, March 15, 2004

Whether you wanted a book or not, I'm giving you one :).  Read Code Complete by Steve McConnel.  It's the single most comprehensive guide to writing good code I've seen.  "Writing Solid Code" is supposed to be good as well, though I haven't read it.

Seriously, it's filled with examples and rational for why various coding styles/habits are good.  Just looking at good code won't tell you *why* it's good (or bad).

Chris Kessel
Monday, March 15, 2004

*  Recent Topics

*  Fog Creek Home