3 ms·
I understand the idea behind the article - explain proxies and have a fun project to do so, so it doesn't get boring as hell - but, in general, can we please st
by xg15 8y ago
I understand the idea behind the article - explain proxies and have a fun project to do so, so it doesn't get boring as hell - but, in general, can we please stop using runtime features of a language to implement syntactic sugar?
Actual syntactic suger can make a program more readable, easier to debug and even more efficient. Those kind of hacks are neither.
It's not more readable because your expressions are limited to the original grammar, so you have to resort to weird compromises. It's harder to debug because you add layers of abstraction (like the proxies here) that have no purpose at all except changing how your code looks. And it's less efficient because those layers of abstraction will still stay with the program when it's being executed even though you only needed them while you were writing the code.
So, please, syntactic sugar is awesome and more thought should be given to letting users add their own sugars - but can we do it via metaprogramming and preprocessors and not by hacks like this?
(Disclaimer: This pattern annoys me to no end in Java, so it's gotten a bit of a pet peeve. No fault to the author of this post who has written an excellent article)
- sametmax 8y agoSometime it's nice. It's what makes numpy, pathlib and sqlalchemy great. Just throwing the baby with the water is never a solution. As usual there is a balance to be found.
- xg15 8y agoAbsolutely. I didn't want to demand that we all stop using sugared libraries in an instant. I'm more hoping that user-defined syntactic sugars and DSLs could be a focus point in future language design - so you actually get compile time tools and debugging support for them and don't have to resort to runtime or modeling hacks to implement them.