Re: Woo hoo ... a whole new set of compiler headaches!! :) - Mailing list pgsql-hackers

From Dave Held
Subject Re: Woo hoo ... a whole new set of compiler headaches!! :)
Date
Msg-id 49E94D0CFCD4DB43AFBA928DDD20C8F9026184CD@asg002.asg.local
Whole thread Raw
In response to Woo hoo ... a whole new set of compiler headaches!! :)  ("Marc G. Fournier" <scrappy@postgresql.org>)
Responses Re: Woo hoo ... a whole new set of compiler headaches!! :)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: Friday, April 22, 2005 10:56 AM
> To: Dave Held
> Cc: pgsql-hackers@postgresql.org
> Subject: Re: [HACKERS] Woo hoo ... a whole new set of compiler
> headaches!! :)
>
> [...]
> I dunno about "fundamentally faster", but "fundamentally more stable"
> I'd agree with.  C++ has never recovered from being a moving target
> for so long.  For a project with any serious ambitions of portability,
> it's a pretty risky choice.

That depends on what features you choose to use.  Certainly if you
incorporate the latest template metaprogramming techniques, you will
run into some portability issues.  But you could easily move to C++
purely for the increased type checking without using all of the
advanced features and get portability on the same par as C.  If you
don't believe me, check out the Boost libraries at www.boost.org.
Most of the changes to C++ since C++98 have been additions to the
Standard Library.  The language changes have been mostly concerned
with defining tricky corner cases that most programmers don't touch.
It's actually very straightforward to write standard C++ and get a
reliable build on all the major platforms.

The only people who really concern themselves with defect reports
and the kinds of issues you see on the standardization mailing lists
are library designers and implementors who are creating state-of-the-
art libraries and intentionally pushing the language to its limits.
There's lots of good reasons to move to C++, even if the codebase
did not take advantage of all the OOP or GP features available.

You have better type checking, C++-style casts, which are safer
if used correctly, inline functions, etc.  Of course, taking
advantage of your basic OOP features like data hiding and RAII
would be a big bonus for a relatively small change.  Then, of
course, you have the controversial issue of exceptions.  I
personally think exceptions are a superior way to handle error
conditions in most cases, but a lot of programmers are slow to come
to that way of thinking.

And because the vast majority of C programs are also correct C++
programs, it really wouldn't be that much effort to port the code.
It would even be possible to do it piecemeal, building some modules
in C++ and exposing a C interface to the rest of the codebase.
Besides the functional advantages I briefly listed, I also find
C++ to be more readable because you can avoid a lot of ugly casts,
and other types of expressions have a more elegant syntax in C++.

I would even be willing to translate a file or two into C++ to
illustrate the difference, if that would be worthwhile.

__
David B. Held
Software Engineer/Array Services Group
200 14th Ave. East,  Sartell, MN 56377
320.534.3637 320.253.7800 800.752.8129


pgsql-hackers by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: Woo hoo ... a whole new set of compiler headaches!!
Next
From: Alvaro Herrera
Date:
Subject: Re: Woo hoo ... a whole new set of compiler headaches!! :)