Writing Bug-Free C/D Code
Henning Hasemann
hhasemann at web.de
Sun Mar 18 23:00:28 PDT 2007
I just start a few little things.
1.)
Most of the bugs I had when starting with D where that I simply forgot
to initialise members in the c'tor:
class Foo {
void foo() { ... };
}
class Bar {
Foo myFoo;
void bar() {
myFoo.foo();
}
}
Of course, because here myFoo is default initialised to null this always gives
a segfault where myFoo is first being used in such a way,
so it is very easy to track down (if you use a debugger at least).
But sometimes I'd find it nice if there was a way to tell D:
Warn me at compile time if it is clear that some class instance members
will be null.
Of course you must be able to tell D exceptions to this, as you will want
to have a few members be null until later.
I have no good idea what this tool would syntactically look like or
if it would make sense to have it a compiler switch or whatever.
Probably the idea is almost bullsh*t nevertheless, because you get
used to initialise your members after a short while.
2.)
Another thing would be easy support for stack traced exceptions.
I tried flectioned last weak or so (just for this purpose) but it
didnt want to compile with my code (I think I was still on dmd-1.007 so
it might have been a bug there). I think STE's are of use
to many developers so they should be put into phobos or so.
3.)
Please change the implicit integral casting rules to be more c-like.
This has been discussed here and I cant remember a good argument
against casting only in such a way data doesnt get lost.
(ie: int->float is okay, but float->int, or int->uint is not)
I had errors that where very hard to track down, because somthing like
(-1 * 4u) yields the unsigned int representation of -4 which is
4294967292, which is rather unintuitive when there is no explicit cast.
I know, changing this might break some code, but I cant help considering
code that relies on such implicit casting rules broken nevertheless.
Henning
--
v4sw7Yhw4ln0pr7Ock2/3ma7uLw5Xm0l6/7DGKi2e6t6ELNSTVXb7AHIMOen5a2Xs5Mr2g5ACPR hackerkey.com
More information about the Digitalmars-d
mailing list