On Syntactic Sugar and Weight

time to read 1 min | 191 words

Greg Young posted about some issues that he run into with yield statements and compile time verifications in Spec#. He ends with:

Given this information are iterators something that are THAT desirable? Iterators are syntactical sugar, I can duplicate what an iterator does rather simply in code that does not use an iterator … Are they worth me giving up the possibility of removing all of my runtime checks or introducing this complexity?

My answer, yes, they are 100% desirable.

OO is syntactic sugar, there is enough object oriented C code out there to prove that, at least. But syntactic sugar matters, it matters because it allows you to reduce the complexity and move it to the compiler.

Take Rhino ETL as an example, the whole thing revolves around the idea of iterators. Making it any more complex than it has to will cause it to be infeasible.

The weight of the pattern or approach has direct correlation to its applicability. Dependency Injection doesn't work without an IoC container around, and iterators are far less useful if you don't have yield to make the pain go away.