Re: Cpp Considered Harmful

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


Date: Tue, 31 Aug 2004 07:44:36 -0400

Kai-Uwe Bux wrote:

> Steven T. Hatton wrote:
>
>> Paul Mensonides wrote:
>>
>>> Assertions are invaluable tools.
>>
>> Some people seem to think so.
>
> Some people, including me, *do* think so.

>> I read up on them in both Java and C++, and was also aware of them in C.
>> They never seemed to be much use.
>
> "Read up on them"? Have you ever used this feature? Sometimes you realize
> that something is useful not from reading about it.

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.

>> I'll grant you, with the weak exception handling of C++ such a thing
>> might be a bit handy.
>
> Assertions and exceptions are completely different beasts. Assertions are
> about aborting the programm and printing a useful statement (useful
> predominantly in debugging). Exceptions provide a flow construct to escape
> from arbitrary levels of nesting (useful predominantly in postponing the
> handling of error conditions).

Actually Stroustrup goes on to demonstrate an alternative form of assertion
which also failed to appeal to me. He uses a template that takes an
invariant as a parameter. And get this. It throws an exception rather
than aborting the program. In general that is the kind of thing I was
talking about, but I simply don't find cluttering my programs with
debugging code a good idea, nor, in general do I find it useful. I've
noticed C and C++ programmers new to Java tend to use stuff like if(DEBUG
{/*...*/} until they realize it really isn't all that useful in that
context.
 
>> Too bad C++ doesn't have printStackTrace. I can't even think of
>> problem I've had where such a mechanism would be of much use.
>
> My debugger prints the stacktrace just fine.

When the code crashes? Will it print it to a web browser when your web
application aborts? How do you use something like abort in a lodable
module hosted by an application server?
 
> * I do not see how that could be useful to anybody.

That is not something I really care about, as long as the feature doesn't
impact anything else.

> * It will not allow me to have my IDE.
This is a very important issue. The availability of superior IDEs for C++
was one of the key features that distinguished it from the pack in the
early days. What I've seen done with Java IDEs has shown me that they can
be extremely powerful. Perhaps the more recent Microsoft IDEs for C++ are
similar in their capabilities to what JBuilder, Eclipse, NetBeans, etc
provide for Java. Something tells me that is not the case.

> * If others can do something like that, I will have to adjust.

Some things I accept as unlikely to change. For example, I don't believe
there will ever be a file naming specification for C++. Some things seem
more significant. For example, the dependence on header files to include
resources. I've seen better ways of handling that situation, and I think
it is a serious impediment to providing far more powerful support to the
language.

> * Bjarne Stroustrup seems to say so.

You may care to note that this thread was forked from a thread I started
with the purpose of questioning one of his more strongly voiced opinions.

> * In Java you cannot do that; and Java rocks.

For the most part, I've pointed to things you /can/ do with Java and
you /can't/ do with C++. There are good ideas in Java. The people who
created the language are not stupid, and they had solid accomplishments
using C (and perhaps C++) before they started working on Java. To ignore
Java, as many C++ programmers would like to do, is an unwise approach to a
legitimately successful competitor to C++.

> * ...
>
> c) May I suggest to replace X by some feature set / mechanism that would
> only allow for the uses listed in (a). [Specifics about the proposed
> replacement are unfortunately missing at this time.]

Well, then you haven't read all of what I've posted. I've been very
specific about what I would like the exception handling to do. I also
posted a fairly extensive explanation of how I believe the Java library
model would work for C++. I also proposed the addition of a feature to
allow for user defined infix operators.

You may also care to notice that I have been persuaded on several occasions
that my proposals were not as viable as I originally thought.
 
>
> 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.

> I like to explore the possibilites, and every once
> in a while, I am really awestruck at how something can be done elegantly
> in C++ in a way that I could not have fathomed.
>
> I do not think that C++ is perfect, but I dislike the direction in which
> you want to push it. To me, it looks as though you are about to cripple
> the language.

How so? By introducing a more elegant, efficient, and effective means of
managing libraries? I know damn good and well that the Cpp is going to be
around for the foreseeable future. That doesn't mean I can't criticize its
use, and proposed solutions for supporting the same functionality without
resorting to using it.

-- 
"[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: Reddit Guys on the Pros and Cons of Lisp
    ... >> I never have to do that with Java. ... > language features, etc. ... They either have the feature or they don't. ... > libraries doing almost the same - for those languages. ...
    (comp.lang.lisp)
  • Re: Why default parameter values where not included in Java
    ... If you create a language with a bunch ... Sun wanted to encourage fast adoption of Java by a very large group ... The issue is not whether the feature could save a few lines of code. ... and the reasons of various team members ...
    (comp.lang.java.programmer)
  • Re: Comparing Lisp conditions to Java Exceptions
    ... All the ISO standards in the world will not make the world ... Nothing keeps you from annotating your program with exceptions based on what ... language should adhere to your theory. ... Curiously, although you don't say it, Java has the opposite problem. ...
    (comp.lang.lisp)
  • Re: casts
    ... This is why most shit programmers refuse to learn languages including ... C Sharp and Java. ... compiler in a later edition of Visual Basic, ... language for processing data. ...
    (comp.lang.c)
  • Re: C, really portable?
    ... > Wait, is Java a modern language superior to C, or is it still ... It is a much better OO language than C++, ... It depends what you are doing, Java aims for rigorous portability - the same ... regardless of platform. ...
    (comp.lang.c)