[M3devel] warning for uninitialized variables?

hendrik at topoi.pooq.com hendrik at topoi.pooq.com
Fri Jun 4 01:36:14 CEST 2010


On Wed, Jun 02, 2010 at 05:44:22AM -0700, Mika Nystrom wrote:
> Jay K writes:
> >
> >Limting the affects by virtue of being safe isn't much consolation.
> >The program can easily go down a "safe" but very incorrect path.
> 
> It is, though!  Do you always know what value to initialize the
> variables to?  If not, you're just picking some value to shut up
> the compiler, and now your code no longer expresses---to a human
> reader---that x is uninitialized.

Not initializing it because thats your intent is OK in the cource code.
But letting the compiler initialize it to some or other value in a 
consistent manner gives the consistency that makes your code more 
rerunnable therefore more debuggable. 

> 
> Remember, code is mainly written for humans!  Computers don't care
> about fancy structuring, declarations, etc.  When you write a program,
> you write it to be read by a human.  The fact that a variable is
> uninitialized is a part of the design of the program.
> 
> It's an unfortunate fact that our languages don't have all the 
> mechanisms necessary to deal properly with uninitialized variables.
> Retrofitting mechanisms to something that just isn't expressive
> enough to solve the problem I really don't think is the way to go.

That's why I like to declare variables at the very point they are 
initialized.  If they are in scope, they are OK.  (Actually, there are 
still a very few cases where you want to declare a variable other than 
where it's initialized.  But that's quite rare).

But Modula 3 has chosen a different path, and I don't think this is 
really retrofittable.

-- hendrik



More information about the M3devel mailing list