[M3devel] [M3commit] CVS Update: cm3

Mika Nystrom mika at async.async.caltech.edu
Wed Jul 7 09:37:53 CEST 2010


Jay K writes:
>
...
>> >When you write VAR a:INTEGER=3D3B
>> >you make the human proofreading your code have to work much harder
>> >to do the data/control flow analysis to make sure you didn't
>> >use the uninitialized value.
>>
>> And yes=2C that's precisely the point!
>
>
>You are just adding to the maintenance cost of the code.
>If something makes it much more difficult to analyze by a human=2C and does=
>n't
>provide much benefit=2C don't do it.
>

Sorry to keep beating a dead horse but I meant precisely the opposite.

If you ever see code that I have written that says:

VAR 
  x : INTEGER;
BEGIN
...
END

that means *precisely* that there is no initial value of x for which
the code is more correct than for any other initial value.  I couldn't
care less (99.9% of the time) about the insignficant time the compiler
spends initializing the variable.  It's all about readability.  If it says

VAR
  x := 0;
BEGIN
...
END

it's really rather a mystery what that 0 means until the human has
analyzed the code and realizes that on every path, x is written before
it is read!  And hey if you introduce a bug in the program where you
forget to initialize x as you thought, the naive reader will assume the
code is correct, because you did initialize it to zero (how clever, that
zero value must be very special!)

If you leave out the extra initialization, the bug will be fairly obvious
even to someone who doesn't know exactly what the program is doing.

I think you are just trading a set of moderately easy to analyze bugs
for a set of very difficult bugs if you insist on initializing every
variable including those without good initial values.

     Mika



More information about the M3devel mailing list