Monday, April 23, 2007

Breaking Changes in Linq, Syntactic Sugar? Syntactic Heroin?

Breaking changes in Linq

Two days into the Linq jungle, I have noticed quite a few breaking changes in C# 3.0 Beta compare to the CTP release last year. The majority of sample code off the web can no longer compile under the new version. The poor documentation (well, to be fair, it's documentation for Beta...) made it a lot worse:

  • System.Query namespace is now System.Linq.
  • System.Expressions is now System.Linq.Expressions
  • Extension methods ToQueryable and ToEnumerable are now AsQueryable and AsEnumerable
  • Sequence class has been substituted with Enumerable, although this likely has no impact on code compilation.
What's "Syntactic Sugar" anyway?
All C# 3.0 new features are described as "Syntactic Sugar" by someone at some point. This leads me to think what exactly is Syntactic Sugar: Is OOP just a web of Syntactic Sugar(think Objective C, for example)? "Member Method" covers up the underlying function with an added this pointer, and the almighty "Polymorphism" is just a short hand for function pointer tables... So where do we end with this stripping process? "MOV EBP, ESP"? Oh, wait, that's just "Syntactic Sugar" for a bunch of 0s and 1s...
Syntactic Heroin
Some called operator overloading "Syntactic Heroin" because of the potential abusive use. I have the same concern for Extension Method: I see the legit use in certain situations, but it's so easy to abuse the concept by using it to quickly "hack up" a incorrectly designed class contract. It's not hard to see the code would become virtually unmaintainable when extension method is overused.