Docs: Section on local variables
Timon Gehr
timon.gehr at gmx.ch
Thu Apr 26 00:26:41 PDT 2012
On 04/25/2012 06:10 PM, Andrej Mitrovic wrote:
> On 4/25/12, Stewart Gordon<smjg_1998 at yahoo.com> wrote:
>> Even if it's left over from debugging, it
>> looks silly, and
>> might lead other people reading the code to believe something's wrong.
>
> There's about a million ways to make code unreadable, and nobody
> writes pitch-perfect code that has absolutely no leftover code or
> comments.
>
> And what if you're refactoring and you do multiple builds every couple
> of seconds? You add a variable, remove it, etc etc. Enabling this
> warning will just make for a noisy compiler. Keeping variables clean
> is the responsibility of the programmer and not the compiler.
>
> If it doesn't affect the semantics of code the compiler should shut
> up. Please don't turn the compiler into a reincarnation of Clippy.
+1.
Another thing: It might not be unused in every static code path.
Even more important:
template isInputRange(R)
{
enum bool isInputRange = is(typeof(
{
R r; // can define a range object
if (r.empty) {} // can test for empty
r.popFront(); // can invoke popFront()
auto h = r.front; // can declare an unused variable
}()));
}
Having these kinds of errors in the compiler would be a major PITA that
butchers the language without any benefit for correct code. This should
not be the responsibility of the compiler. It is not a good match for D.
More information about the Digitalmars-d-learn
mailing list