Docs: Section on local variables

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Sun Apr 22 01:59:57 PDT 2012


"H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote in message 
news:mailman.2018.1335019794.4860.digitalmars-d at puremagic.com...
> On Sat, Apr 21, 2012 at 02:14:14AM -0700, Jonathan M Davis wrote:
>>
>> init solves the larger problem of uninitialized variables being
>> garbage and resulting in non-deterministic behavior. And it solves it
>> in more places than the Java and C# solution does, because it deals
>> with stuff like initializing all of the elements in an array when it's
>> first allocated, which they don't AFAIK.
>>
>> True, init doesn't make it so that programmers always remember to
>> initialize all of their variables, and with a default-initialized
>> variable, you have the ambiguity of whether the programmer meant to
>> use the default or whether they forgot to initialize the variable, but
>> that's minor in comparison to uniitialized variables being garbage
>> values. And since there's nothing to stop a programmer from
>> initializing a variable with an incorrect value, the fact that a
>> variable is directly initialized by the programmer in Java and C#
>> doesn't necessarily solve that problem any better anyway. And then
>> there's also the irritation of the occasional forced initialization,
>> because the compiler's flow analysis isn't good enough to detect that
>> it's unecessary.
> [...]
>
> Hold on a second here, I thought the original complaint was that
> *unused* local variables should generate a warning? What has that got to
> do with .init? [...]

There were two original points. Warnings on unused locals was one. The other 
was this which, apperently, is still in the docs from, what, almost a decade 
ago?:

"Local Variables
It is an error to use a local variable without first assigning it a
value. The implementation may not always be able to detect these
cases. Other language compilers sometimes issue a warning for this,
but since it is always a bug, it should be an error."

>
> -- 
> "You are a very disagreeable person." "NO."

That reminds me of one of mine, which I kinda liked at first, but then was 
never really sure the intended irony of "agreeable asshole" came across 
quite like it was supposed to: 
https://www.semitwist.com/articles/article/view/seriously-do-i-even-read-any-of-the-crap-i-write...

(Ugh, the trailing dots are apperently part of the URL. Stoopid 
off-the-shelf CMS...)




More information about the Digitalmars-d mailing list