Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Unlike with LINQ, if these operators did not exist in Smalltalk, it would be trivial to add them.

False. The SQL-like snippet of LINQ in the article is just syntactic sugar for

    people.Where(person => person.Type == PersonType.Adult && && person.Location != "New York")
Which is implemented via a static class extension method. C# doesn't ship with a Zip method, but adding one is trivial:

    public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
      using (IEnumerator<TFirst> e1 = first.GetEnumerator())
        using (IEnumerator<TSecond> e2 = second.GetEnumerator())
          while (e1.MoveNext() && e2.MoveNext())
            yield return resultSelector(e1.Current, e2.Current);
    }
That makes it a library feature of C#, not a language feature. Only the LINQ syntactic sugar is a language feature, and I would argue the decision to include such a syntax was a bad one.


Actually, still true. You're right that LINQ expressions are syntactic sugar for C# calls, but that syntactic sugar depends on lambdas (introduced in C# 3) and expression trees (also introduced in C# 3), among others. You cannot write LINQ as you know it in C# 2. That's my point.


Heh. You still have anonymous delegates in C# 2.0, and you can roll your own expression trees if you really want them. Same thing for yield and extension methods. Of course your code will be much more verbose and unnatural, and you won't have as much compiler support.

Yes my friends, we are deep in the Turing Tarpit, where the boundary between language and library is blurred, baroque architecture looms menacingly in the mist, and the bare metal is somewhere far below the fetid surface of the swamp. I hope you brought your safari hat and your elephant shotgun.


Ok, but using the previous version of the language to demonstrate your point is much less interesting. Additionally, there is the issue of clarity: when I read "C#" I tend to assume that means the language as it exists today, not some previous version.


You completely missed the point of the article, which was that I can add these features to the language without waiting on the language designer. Microsoft added three key technologies to C# 3, one of which was syntactic sugar for the other two. That's irrelevant to my point.


Agree with you about the syntax. Three years ago at LtU we tried to coax technical justifications out of Microsoft's Erik Meijer and got no answers whatsoever: http://lambda-the-ultimate.org/node/1253#comment-13824




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: