News for hackers. Stuff that matters.
Re:C# 8: Switch expressions by LandR on Friday February 15, 2019 @10:42AM (#19171761)
That is ugly.

What he's doing is creating an anonymous function which takes no parameters and returns an int. That's what a Func<int> is, and then he is executing that function, that's the () bit after }))

He could write it nicer as:

   "+" => Add(),
 
Where he defines add as

   int Add() => a + b;
He's just doing too much inline, 99% of C# developers would not write code as he has done there.

Its' the bloggers code style that is the problem here, not the new switch syntax. Although he probably did it to make the example more self contained and terse.

Re:C# 8: Switch expressions by Dylan16807 on Friday February 15, 2019 @02:24PM (#19173890)
> He's just doing too much inline

It's two short lines.

The problem is that he's writing a small but more than one line bit of code, so the overhead of the anonymous function is just as big as the code itself, and arguably more complex.

Re:C# 8: Switch expressions by rattray on Friday February 15, 2019 @11:26AM (#19172141)
I agree with your conclusion, but let's keep the conversation civil.
Re:C# 8: Switch expressions by kayamon on Sunday February 17, 2019 @07:02PM (#19187711)
The conversation is quite civil already.
Re:C# 8: Switch expressions by rattray on Sunday February 17, 2019 @09:57PM (#19188319)
Ah, too late to edit/delete my comment. They edited their post, perhaps in response, which is now much more considerate.