Wish: Variable Not Used Warning

Markus Koskimies markus at reaaliaika.net
Thu Jul 10 05:35:01 PDT 2008


On Thu, 10 Jul 2008 12:00:15 +0000, Markus Koskimies wrote:

An addition; I wouldn't mind (in fact I would hail) if all unused parts 
would be declared as an error in D spec. Unused/uninitalized vars, 
private members, dead code blocks and such are normally produced when you 
have had an intensive coding session to change some internals, but you 
have not remembered to change the behavior in every affected places. At 
least I never intentionally do dead code, they always mean that I have 
forgotten to do something. Furthermore, D has so many powerful tools for 
quickly "out-commenting" dead code (like "/+ ... +/" and static if) that 
it should not be a problem.

There are some harder-to-detect -things, just like infinite loops. I 
think that it is always an error to make a compiler-detectable infinite 
loop (or if statement) using comparison operators (even if there are 
reachable breaks or exception-throwable calls inside of it), like:

	for(; -1 > 0 ;) { ... }

"for(;;)" is valid for those, as well as "while(true)". "if(true)" would 
be better to be written "static if(true/false)".

Signed-unsigned -comparison is easily unintentionally made, since most 
programmers use int extensively and library functions return size_t and 
similar types, which can be unsigned. IMO it is a clear programming 
error; 



More information about the Digitalmars-d mailing list