A nice way to step into 2012

Timon Gehr timon.gehr at gmx.ch
Sat Dec 31 07:58:31 PST 2011


On 12/31/2011 12:51 PM, Don wrote:
> On 2011-12-27 23:27, Timon Gehr wrote:
>> In case the function is used for code generation, it can get
>> rid of one level of indentation.
>> string generate(string x) => mixin(X!q{
>> @(x) = 2;
>> });
>
> That just makes it look even more like Perl. The return statement is not the problem.

The indentation is the problem. If you don't like @(x) = 2; then that is 
an unrelated issue.

>
>> My intention is that it would be used with short expressions. Such
>> monster expressions as in your example are rare in real world code.
> That's my point.

On the contrary. The longer the expression, the less it buys you in 
readability/the less typing it saves.

> The BEST CASE is that you save 6 characters, on

This is the worst case, if it is applicable. The best case is saving an 
unbounded amount of characters.

> something which was already easy to read. I don't think it buys you
> anything in readability. Really, nothing at all.

Those 6 characters are probably the majority of the characters in the 
function body. It saves you more than 6 characters. It saves you 6 
characters _every time_. For 10 short functions, it saves 60 characters. 
For 100 short functions, it saves 600 characters, etc.

We should probably stop that discussion soon, because there is no 
objective readability measure and therefore it is unlikely that one of 
us will change his opinion.

Anyway, it certainly improves language uniformity. Is there any case to 
be made against generalizing => ?


More information about the Digitalmars-d mailing list