tag:blogger.com,1999:blog-22587889.post8964165679579232414..comments2024-02-11T13:21:47.930+05:30Comments on Ruminations of a Programmer: Syntactic Sugars - What makes them sweet ?Anonymoushttp://www.blogger.com/profile/01613713587074301135noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-22587889.post-36789955496550353272008-04-24T08:14:00.000+05:302008-04-24T08:14:00.000+05:30I tend to agree that most of the time, the ability...I tend to agree that most of the time, the ability to add syntactic sugar is useful. In order of power, we've got things like C's macros, functional constructs that look like syntax (like Scala), syntax so flexible that it obscures the boundary between idiom and DSL (Ruby), and at the top you've got true macro systems like Lisp.<BR/><BR/>But although this is OFTEN helpful, there is also a dark side to adding syntactic sugar. It is similar to operator overloading in C++: useful for creating complex numbers or smart pointers, but I've seen SQL libraries that abused it to the point of incomprehensibility. The danger of adding new syntactic constructions is that they are familiar only to someone who has seen them before -- typically someone already familiar with that body of code. Used sparingly, they can make code more readable, but overused they can make code readable *only* to someone with deep background knowledge. And readability is one of the most important properties.<BR/><BR/>So I like introducing new syntactic constructs, but I always think twice before doing so, and only take the plunge if I think it would be more readable EVEN to a reviewer who had to interrupt their reading to go look up the construct. Compressing 30 lines to 1 is a clear win, especially if repeated in many places; compressing 2 lines to 1 is unlikely to be worth the cognitive load.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-22587889.post-87668009707899657142008-04-22T16:57:00.000+05:302008-04-22T16:57:00.000+05:30It's all around "Syntactic sugars, when properly d...It's all around <BR/>"Syntactic sugars, when properly designed, reduce the semantic distance between the problem domain and the solution domain."<BR/><BR/>The other can be easily excluded.Anonymousnoreply@blogger.com