Hacker News new | ask | show | jobs
by Invisig0th 2687 days ago
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.

5 comments

That's the general nature of a turing complete language. The purpose of every feature is making things less ugly.
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.

LINQ is surprisingly powerful when you start overloading SelectMany, as that allows you to implement Monads nicely.
Do you know what "expression trees" are and how they relate to LINQ?