Re: Cpp Considered Harmful

From: Steven T. Hatton (susudata_at_setidava.kushan.aa)
Date: 08/31/04


Date: Tue, 31 Aug 2004 12:35:41 -0400

Kai-Uwe Bux wrote:

> Steven T. Hatton wrote:
>

>> There has to be some need I have before I look for something to fill it.
>> The idea of aborting a program on failure is simply not something I
>> believe to be a good practice.
>
> That is why assertions are preproccessed away in production code. And of
> course, the preprocessor would allow you to write an assertion macro that
> does not abort.

It was really a philosophical point. I don't want my code to abort for any
but absolutely unrecoverable circumstances. I started working with
hardware in 1979. failing to maintain an operational system was not merely
bad for my reputation, it was a threat to national security. My more
recent experience has been of the same nature. Add to that the fact that I
was developing code to run on servers, as services. Crashing the server
was just not a good development strategy. Especially because I was the
sysadmin.
 
> An assert( blah ) line is not cluttering your program with debug code but
> a concise way of stating an invariant (e.g., within a loop, at the entry
> of a block, or before a return statement).
>

I believe I understand the strategy. In the kinds of development I've done
I haven't seem much need for that kind of thing. I'm more likely to want
to leave dumpers that will spit all the members of a class out to a stream.

 
> Admittedly not. I was thinking of a debugging session to get my code right
> so that it would not crash in the field.
>
But that's the nature of application servers. A single application should
not bring down the server. I'll admit I have very little experience with
C++ in that area, so there may be ways to call abort and only crash the
service, and not the server.

>> For the most part, I've pointed to things you /can/ do with Java and
>> you /can't/ do with C++.
>
> This is an interesting point. I would like to make a distinction. I think
> you pointed to things you *can know* in Java but you *cannot know* in C++.
> In C++, because of the preprocessor, you cannot really be sure that what
> you read is not transformed into something entirely different. Because of
> conditional compilation, you cannot know which headers are included in
> which order. Because of the flexibility of throw(), you cannot be sure
> about the type of the object thrown. All these things are things you
> cannot know about, because of things you (or others) *can do*.

Yes. You are correct. Information technology is about information. Good
solid easily obtainable information is vital to design, to implementation,
to trouble shooting and to security.
 

>>> In short, you want to enforce coding policies by language design. I,
>>> however, like C++ precisely because it does not enforce policies but
>>> provides mechanisms, and a lot. E.g., [try, throw, catch] to me is not
>>> about error handling but about stack unwinding; and your suggestion that
>>> throw() should only accept arguments derived from std::exception would
>>> break some of my code.
>>
>> Then you didn't read all of what I wrote about the topic. Either that,
>> or you chose to ignore it.
>
> It is a pitty that you chose to pick on the example and did not address
> the main point that I raised int the topic sentence. I appologize if I
> mischaracterized your opinion on exceptions. I still feel that you prefer
> the language to enforce policies rather than have it provide mechanisms.

In the case of exceptions, I have solid experience that supports the
opinions I hold. What I suggested simply works better as a default. And
that is what I was referring to when I suggested you hadn't read everything
I wrote. I explicitly said that the should be configurable through some
mechanism similar to the one currently used to switch out handlers. I'm
not sure how that might be accomplished, but I suspect someone in the C++
community is capable of finding a means.

> To take your last paragraph as an example: You start by talking about
> library management when finally addressing the preprocessor in the
> negative. This creates the subtext: "library management is *the*
> legitimate use of the preprocessor, let's find a better way to that (so
> that hopefully nobody will use the preprocessor anymore)."
>
> Again, I am not saying that policy enforcing is a bad idea. I just prefer
> to have at least one really powerful language around that does not do
> that. And I like C++ to be that language.

Actually, to a large extent, it's the other way around. I believe the
library management in C++ stinks. If there were a better system - which I
believe is highly doable - I would have far less to complain about
regarding the CPP. The CPP does go against certain principles of
encapsulation that are generally regarded as good in computerscience. A
better library system would go a long way toward addressing that as well.
If people aren't #including 15 megs of source in every file, there is less
(virtually no) opportunity for hidden variables entering the environment.

-- 
"[M]y dislike for the preprocessor is well known. Cpp is essential in C
programming, and still important in conventional C++ implementations, but
it is a hack, and so are most of the techniques that rely on it. ...I think
the time has come to be serious about macro-free C++ programming." - B. S.


Relevant Pages

  • Re: Question about Leverage source from Different Projects
    ... conditional preprocessor stuff INSIDE the stdafx.h depending on the project macro defined. ... There is, as far as I can tell, not even a discussion of the .cpp files, just a strange ... #pragma message ...
    (microsoft.public.vc.mfc)
  • Re: Conditional compilation sans the cpp
    ... a design for some kind of macro firewall that is supposed to isolate code ... from an effects from the preprocessor. ... I fully understand that the CPP has been used to to some great stuff. ... "There is only One inviolable Law" ...
    (comp.lang.cpp)
  • Re: delete comments in .c file
    ... Assuming you have access to the C preprocessor (cpp) you can do a quick hack ... Isolate the file from it's include files and run like, ...
    (comp.lang.c)
  • Re: To bean or not to bean
    ... Qt development begain in 1991, and the first public release was on the 20th ... The preprocessor is the main reason that there is no serious C++ contender ... techniques it supports do not scale to that level of programming. ... and the Cpp than he does. ...
    (comp.lang.cpp)
  • Re: Is Global Copy Possible?
    ... You certainly COULD create your own "preprocessor" to do this. ... For information on how to create and access such a thing in Server Express 4.0, ... > program belonging to an application without explicitly using a COPY ...
    (comp.lang.cobol)