Re:C# 8: Switch expressions
by goto11 on Friday February 15, 2019 @02:10PM
(#19173755)
C# 2 did not have Linq. Linq is the best feature ever.
[ Parent
| on HN ]
Re:C# 8: Switch expressions
by Invisig0th on Friday February 15, 2019 @02:35PM
(#19173999)
Actually, adding LINQ to C# did not introduce any new functionality at all. Everything you can do in LINQ you could already accomplish in C# without LINQ. Yes, I suppose someone could say that the older code was uglier, but it already had the same capabilities as LINQ.
That's been the case for the majority of supposed "new features" in C# for at least the past 8 years or so -- LINQ, inline variables, anonymous functions, string literals etc. It's all just syntactic sugar on top of existing features.
Re:C# 8: Switch expressions
by Dylan16807 on Friday February 15, 2019 @02:38PM
(#19174020)
That's the general nature of a turing complete language. The purpose of every feature is making things less ugly.
Re:C# 8: Switch expressions
by Invisig0th on Friday February 15, 2019 @02:54PM
(#19174149)
I'd say it's more the general nature of Microsoft in this particular case. "There should be three different ways to do that" has been the case since Windows 3.1.
There is no way you can implement Linq in C# 2.0. C# 2 does not have lambdas and expression trees, so you cannot write an expression which can either be compiled into regular code or into an expression tree depending on context.
IIRC, LINQ can be translated to C# 3.0 without LINQ, so I guess it is syntactic suger but for C# 3.0. To implement it in C# 2.0 one would need to replace expression trees with “home made” query specification classes. It would be a lot of work, it would not be standardized, and it would not be integrated in the language.
So the real new feature in C# 3.0 are the expression trees. LINQ is only one place where expression trees are used.
Re:C# 8: Switch expressions
by contravariant on Friday February 15, 2019 @03:09PM
(#19174250)
LINQ is surprisingly powerful when you start overloading SelectMany, as that allows you to implement Monads nicely.
Re:C# 8: Switch expressions
by balfirevic on Friday February 15, 2019 @04:50PM
(#19175038)
Do you know what "expression trees" are and how they relate to LINQ?