declaration of variables?

Alex Martelli aleaxit at yahoo.com
Mon Feb 17 09:06:45 EST 2003


Steven Taschuk wrote:
   ...
> I entirely agree that variable declarations cost more than their
> value.

Nice to agree on something;-).


> Your latter point of orphaned declarations, however, has an easy
> answer: a compiler which issues errors for variables used but not
> declared should also issue warnings for variables declared but not
> used.

In C++, at least, the compiler cannot say whether a variable is
"used" whenever it has a user-defined destructor.  E.g.:


#include "mylock.hpp"


void withalock(void (*anyfunc)())
{
    globallock alock;
    anyfunc();
}


A compiler that warned about THIS common idiomatic use of "resource
acquisition is initialization" would draw well-deserved ire, IMHO.

Warning about non-use of variables of types that *don't* have
user-defined destructors may be OK (hiding code in a ctor without
any corresponding code in a dtor may be legal but I don't think
it's ever _idiomatic_ use, so a warning may be ok for that).


Alex





More information about the Python-list mailing list