Performance penalty for using ranges

bearophile bearophileHUGS at lycos.com
Sun Aug 25 14:38:07 PDT 2013


Andrei Alexandrescu:

> I don't see why the excitement around anonymous bindings. It's 
> a rare case and it's not like we're running out of symbols, 
> particularly given they're by definition written only once :o).

It's not a rare case, I can test this searching in my code for 
"foreach (_;".

And while not essential, anonymous loops are useful because 
adding an useless variable to your code increases its complexity 
a little without giving something back. It's just like adding an 
useless variable inside one of your functions. In C/C++ I look 
for the "unused variable" warnings (a warning that is currently 
missing in D).

When you define a function, and you don't want to use its second 
argument, D allows you to not give it a name, despite you are not 
running out of symbols:

void foo(int x, int) {}

When I see code with a loop with a variable, to understand the 
loop I first of all search how such variable is used inside the 
loop. If the loop variable is anonymous this tells me something 
important about the loop, and reduces the noise.

Bye,
bearophile


More information about the Digitalmars-d mailing list