Missing compiler warning?

Chris wendlec at tcd.ie
Mon Oct 21 03:50:44 PDT 2013


On Monday, 21 October 2013 at 09:36:48 UTC, Jonathan M Davis 
wrote:
> On Monday, October 21, 2013 11:24:06 Chris wrote:
>> But there you have this. But a function (in the same class) 
>> like
>> 
>> void processInput() {
>>    auto input = // ...
>>    // 20 lines later
>>    input = std.string.format("Hello %s!", someString);
>> }
>> 
>> Why would one want to write code like this? Why should a
>> short-lived local variable assume the name of a class variable?
>> This is a source of confusion and I don't consider this good
>> practice. Maybe it's just personal taste.
>
> That may very well be bad practice (I certainly wouldn't advise 
> writing code
> like that), but it's also not definitively wrong. Unless it's 
> definitely a bug,
> I think that the compiler should keep quiet about it, because 
> anything that it
> yells about has to be treated as a bug, and we shouldn't be 
> forcing people to
> change their code just because there _might_ be a bug in it.
>
> - Jonathan M Davis

So the solution would be an additional layer that can be turned 
on / off. Warnings like "unused variable" or "shadowing class 
declaration" are quite useful. I don't see any other cases where 
a warning would be nice (at the moment).


More information about the Digitalmars-d mailing list