r/programming • • Sep 26 '09

Ask Proggit: What are the most elegantly coded C/C++ open source projects?

I've recently been reading (parts of) the source for sqlite3 and found it to be a revelation in good programming practise.

What other C/C++ open source projects (of any size) would you recommend that I look at, in order to get an idea of current good practise?

145 Upvotes

292 comments sorted by

View all comments

Show parent comment

17

u/aveceasar Sep 27 '09

Given the failure of BeOS

Now, that's loaded word - "failure"... if you evaluate software solely on its commercial success, MS Windows has to be the greatest software ever... ;)

Adding virtual methods to OS classes will break application's that used the original class version.

So, don't add... if you need to add features, derive...

2

u/[deleted] Sep 27 '09

BeOS is still alive and kicking. http://www.haiku-os.org/ In fact they just had an alpha release as somebody finally got GCC4.3.3 bootstrapped on their OS.

In answer to the question tho: C is a very different beast than C++. C is a procedural language while, C++ is object oriented AND procedural. So best practices in C contradict with best practices in C++. However, learning to program well in a particular languages lends to a firm grasp on the fundamentals, so as someone has probably pointed out: http://www.parashift.com/c++-faq-lite/index.html is your first stop.

2

u/ooffoo Sep 27 '09

So, don't add... if you need to add features, derive...

This usually is not possible when releasing new versions of operating systems. If you want to add new functionality that all Window objects can use then you want to add the functionality to the base Window object. Adding a new derived class is no good since existing applications don't derive from that new class.

What usually happens in C++ projects is they implement some other object system on top of the C++ one. Often a COM style, or factory driven approach.

I used the word 'failure' in the sense of proving C++ as a viable language for operating systems. BeOS went through at least two releases which required applications to be rebuilt from source. This killed the application user base and made it hard to consider it as a realistic target for applications.

BeOS 4.5 and on was better in that they were more careful about breaking backwards compatibility.

0

u/aveceasar Sep 27 '09 edited Sep 27 '09

If you want to add new functionality that all Window objects can use then you want to add the functionality to the base Window object.

If the application wants to use new functionality, it has to be recompiled anyway...

EDIT: ok, I wasn't really paying attention... <sheepish grin/> I see what you mean...

1

u/GNUGeist Sep 27 '09

I think this thread will agree:

BeOS is a good C++ example that would answer the proggit (or whatever they call it).