[M3devel] warning for uninitialized variables?

Jay K jay.krell at cornell.edu
Fri Jun 4 01:47:00 CEST 2010


Declare at initialization is good.
  Exactly what C++ supports and it is considered completely uncontroversial and maybe C9x even supports it.
 
 
Modula-3 supports it, both with "WITH..DO" and "VAR..BEGIN" but at too high a syntactic cost -- having to indent for each new block of variables, or to use begin/end without indenting.
 
 
Heck, C supports the same thing -- you can introduce braces anywhere, and then variables after any left brace.
 
 
I would rather move all my variables to the top of the function and initialize them with 0 than to indent every time I want a new variable. Really. I have learned to accept much about Modula-3's syntax, but not this.
 
 
 
 - Jay


----------------------------------------
> Date: Thu, 3 Jun 2010 19:36:14 -0400
> From: hendrik at topoi.pooq.com
> To: m3devel at elegosoft.com
> Subject: Re: [M3devel] warning for uninitialized variables?
>
> 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