Docs: Section on local variables

Stewart Gordon smjg_1998 at yahoo.com
Thu Apr 26 11:46:38 PDT 2012


On 26/04/2012 15:05, Stewart Gordon wrote:
<snip>
> http://d.puremagic.com/issues/show_bug.cgi?id=7989

 From JMD:
"The fact that isInputRange and isForwardRange rely on
declaring variables which aren't used being legal. It would be really annoying
for unused local variables to be illegal when dealing with template constraint
stuff like isInputRange and isForwardRange. Code would have to be needlessly
contorted to deal with that fact, and you wouldn't ever get a good error about
why the result of the template was false, because it would be part of a
template constraint.

IHMO, the very issue that this bug report brings up highlights a good reason
why unused local variables should continue to be ignored by the compiler."

(on 3960)
"I think that issue# 7989 is a great argument for why there shouldn't be any
warnings or errors for unused variables. Such would needlessly make writing
template constraints harder."

Since this is relevant to both issues, I'll continue the discussion here.

I can begin to see why it makes errors for unused variables a bad idea.  But why no 
warnings?  Obviously the user wouldn't like to see warnings thrown at them when they try 
using templates with such constraints.  But:

- The average programmer is, the vast majority of the time, not writing template 
constraints, but trying to write bug-free application code.
- A quality compiler would swallow warnings generated by the content of IsExpressions, 
just as it already swallows errors generated by them - the only difference being that 
warnings don't cause the IsExpression to return false.

Stewart.


More information about the Digitalmars-d-learn mailing list