Docs: Section on local variables

bearophile bearophileHUGS at lycos.com
Sat Apr 21 09:42:06 PDT 2012


H. S. Teoh:

>> Why do you want to be able to declare local variables and then 
>> never use them?
> [...]
>
> It happens a lot when you're debugging code (temporarily 
> comment out
> some stuff for testing purposes). It would be a major pain if 
> every
> single time you need to temporarily suppress a section of code, 
> you also
> have to hunt down every last stray variable that's now no longer
> referenced in the function and comment them out as well. And 
> then do the
> reverse after you're done testing whatever it is you're trying 
> to debug.

How do Go programmers cope with this (I think in Go unused 
variables are errors)?

So are you saying that in 'finished' code (when you aren't 
working on it) you don't want unused variables? So do you prefer 
just an unused variable warning that comes out only when you use 
"-wi/-w"? A problem I've seen in D.learn is that lot of people 
here doesn't seem to use -wi/-w. Or maybe, on the contrary, this 
unused variable error should be suppressed only if the D code is 
compiled with "-debug"?


> (Yes, yes, I know variables are supposed to be declared right 
> before
> they're used, not at the top of the function... but sometimes 
> things
> move apart after enough code iterations.)

Then adding some pressure to remind to keep such distance short 
may be a good thing :-)


And beside unused variables, there is also this:
http://d.puremagic.com/issues/show_bug.cgi?id=4694

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list