On 28.12.2011 17:41, Jacob Carlborg wrote:
On 2011-12-27 23:27, Timon Gehr wrote:
On 12/27/2011 05:25 AM, Andrei Alexandrescu wrote:
https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc




Andrei

Great! =)

What about making => syntax available to named functions as well?

class C{
private int x;
int getX() => x;
}


void main(){
int[] arr;
bool isOdd(int x) => x&1;
writeln(arr.filter!isOdd());
}


I wouldn't say no to that.


I don't think it improves readability, since it doesn't occur in arbitrary contexts. It'll always be the only thing on the line.
I think that example is close to the best case, but

bool isOdd(int x) { return x & 1; }

is not terribly difficult to read.
So all you're doing is saving 6 characters + one space.
The longer the return expression becomes, the less it matters.

real isComplicated(int param1, Foo param2, real param3) => 43.4 * foo(param2, bar(param2, param1 + param3 * param3,), 556.4 * param1) + param3 + param1 *param2 * param2.baz(param1 + 46, param1*2.46);

doesn't look any more readable than the equivalent code with a return statement. Especially not in the member function case.

Reply via email to