Null references (oh no, not again!)

Walter Bright newshound1 at digitalmars.com
Wed Mar 4 10:28:17 PST 2009


Denis Koroskin wrote:
> Another question is the feature's usability. It might turn out to be not 
> very handy to have all variables initialized, but we can't know until we 
> really start using it, right?

I've used compilers that required explicit initializers for all 
variables. Sounds great in theory, in practice it *causes* bugs.

What happens is the compiler dings the user with "initializer required." 
The user wants to get on with things, so he just throws in an 
initializer, any initializer, to get the compiler to shut up.

The maintenance programmer then finds himself looking at:

int x = some_random_value;

and wondering why that value, which is never used and makes no sense 
because the rest of the logic assigns x a proper value before it gets 
used anyway. So he wastes time figuring out why that dead initializer is 
used.

Then the next maintenance programmer, with a poor understanding of the 
code, changes the logic so now x's some_random_value actually gets used, 
and bug happens.

In general, it's a bad idea to force the user to throw in dead code to 
shut the compiler up. A particularly illustrative case of this is Java's 
exception specification, which they loosened up after it became clear 
that this was not a good idea.



More information about the Digitalmars-d mailing list