[M3devel] warning for uninitialized variables?

Mika Nystrom mika at async.async.caltech.edu
Wed Jun 2 17:32:20 CEST 2010


Jay K writes:
>
>Well=2C I'm certainly not lobbying hard for that=2C presumably there is no =
>efficient implementation=2C esp. for full range integers.
>
>Wikipedia has a nice article. "nice" means "agrees with me".
>
>
>http://en.wikipedia.org/wiki/Uninitialized_variable
>"it is a programming error and a common source of bugs in software."

I don't think anyone disagrees too strongly with that, Jay, but
the question is what can be done about it.  I think the sad answer
is, "not much."

>
>
>And then they point out how Java requires mechanically verified initializat=
>ion of locals.

One might equally well say that an infinite loop is a programming error
and a common source of bugs in software.

Some good people, accordingly, insist that every loop be accompanied by
a proof of termination.

The difference is, of course, that it is obvious that there are
useful loops that we cannot ever expect a compiler to be able to prove
termination of (on its own), whereas "some people feel" that there are
no useful ways of initializing variables that could not be verified
correct by a particular implementation of the Java compiler.

I think that if you take a step back from the problems you will see
they are in fact the same problem: they both breach the "undecidability
barrier".  This is because we haven't put enough information in the
variable declarations themselves to deduce what is wanted.  EWD's chapter
is a start on that---how to do this statically.  (That's the last time
I'm going to plug that chapter, I promise.) 

Modula-3 actually has some very nice mechanisms for avoiding uninitialized
variables.  The ability to declare/initialize a variable from an
expression without providing an explicit type is one.  WITH is another.
I almost never have problems with uninitialized variables in my Modula-3
programs.  Almost...

    Mika



More information about the M3devel mailing list