[linux-elitists] Nobody's favorite language? C++ and free software

Martin Pool mbp@samba.org
Tue Apr 1 17:22:23 PST 2003

On  1 Apr 2003, Nick Moffitt <nick@zork.net> wrote:
> begin  Aaron Sherman  quotation:
> > > I think that the biggest argument for C++ vs. C is that people try
> > > to do things that are native to C++ in C and it leads to
> > > inelegance. 
> > 
> > In C it leads to things like GObject, which IMHO is the heart of
> > elegance. 
> 	I really don't like it.  I don't like maintaining separate
> class and object structures, or having to update massive parallel data
> structures to maintain a big type system.  My method of "polymorphism
> in C" is nice because it *doesn't* try to add any features to C that
> aren't already there.

Your method is just directly casting from one class to the other,
having arranged that they will have a common prefix?  That's fine, if
simplicity is the only thing you care about.  But what will happen
when one of your casts is incorrect, and you have a pointer of the
wrong type floating around.  At some time in the future it will
misteriously fail.

For a system that's meant to support large applications and to be
reasonably robust, making it so easy to create bad pointers is
undesirable to say the least.  OK, then: you add a little dogtag to
the start of each structure giving its type, and then write some
macros that perform the cast and also check the dogtag.  Bugs are now
enormously easier to trap during testing.  If you really want, you can
snip it out for nondebug builds.  

Of course the dogtags have to be designed so that you can work out
both upward and downward casts safely.  If you want the library to be
extensible, then plain integers won't cut it, you need some kind of
metaclass object.

Go a couple more steps down this road and you have GObject.  It really
is a very elegant and well thought out system for robustly doing
objects in C.

> 	If you need a language that can be modified this much, use
> LISP for krissakes.

C macros and functions are a poor imitation of real metaprogramming,
but they have the advantage of a wide audience.

Anyhow, if GNOME was written in Lisp, which of the 20-odd incompatible
free interpreters would it use?


More information about the linux-elitists mailing list