Re: Undefined behaviour [was Re: The D Programming Language]
Al wrote:
Ian McCulloch wrote:
<snip>
Right - and there are systems that already do this. Valgrind (
http://www.valgrind.org/) springs to mind at this point. In the face of a
programming error, you want as much `undefined' behaviour as possible, to
give the tools that detect such behaviour the most information possible.
I think valgrind is the single most useful debugging tool on Linux, even
though I don't use it that often, much less frequently than a debugger, or
even printf() debugging[*]. AFAIU valgrind would be completely useless for
debugging java programs, which leaves a few possibilities: (1) the Java (or
D?) language design is such that bugs that are typically caught by valgrind
would never be made in the first place, or (2) Java debuggers already cover
this functionality, or (3) Java programs are harder to debug than C++
programs. I wonder which?
Java World:
+-------------+
| Logic Bugs |
| |
+-------------+
C++ World:
+-------------+-------------+-------------+-------------+
| Logic Bugs | Pointer | Reference | Threading |
| | Bugs | Bugs | Bugs |
+-------------+-------------+-------------+-------------+
| Sequencing | Misc. | Other UB | Nasal |
| Bugs | Memory Bugs | Bugs | Demons ... |
+-------------+-------------+-------------+-------------+
This is getting ridiculous. First, of course, the alternatives
to "logic bugs" are "typos", etc. Wrong logic is one way of
introducing an error into the program.
Secondly, of course, except for nasal demons, Java has all of
the problems you mention for the C++ world. (And the
implementations I use do guarantee that my program won't cause
nasal demons to fly out of my nose.) Not always in as acute a
fashion, perhaps, although in some cases... C++ under Posix is
actually offers less possibilities for threading bugs than Java
does. And pure standard C++, of course, offers 0 possibility
for threading bugs, because you can't write a multi-threaded
program in standard C++. (Similarly, certain types of C++ bugs
can't appear in Java because there are useful things you cannot
do in Java.)
I agree. But each instance of undefined behaviour needs to be treated on
its merits. There are surely at least a few places in C++ where undefined
behaviour isn't very helpful, or easy to diagnose.
I would really like to know what the "merits" of undefined behavior are,
other than issues dealing with /potential/ performance degradation.
It depends on which undefined behavior you are talking about.
C++ definitly has too much gratous undefined behavior, which has
no redeeming merits. At the other extreme, if you want to write
things like device drivers, using memory mapped IO, you're going
to have to do some pretty funny things with reinterpret_cast;
undefined behavior at the language specification level is
essential here, in order for the implementor to define something
totally arbitrary which covers the need.
In between, there are the performance issues, and Java also has
some undefined (and some underspecified) behavior because of
them, just like C++.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]