Docs: Section on local variables

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Apr 21 07:58:35 PDT 2012


On Sat, Apr 21, 2012 at 01:03:13PM +0100, Stewart Gordon wrote:
> On 20/04/2012 01:53, Andrej Mitrovic wrote:
[...]
> >It is an error to declare a local variable that is never referred to.
> >Dead variables, like anachronistic dead code, are just a source of
> >confusion for maintenance programmers.  "
> <snip>
> 
> 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.

(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.)


T

-- 
Democracy: The triumph of popularity over principle. -- C.Bond


More information about the Digitalmars-d-learn mailing list