Re:A few tips for writing macros in Clojure
by bendyorke on Sunday May 08, 2016 @09:25PM
(#11656980)
The article says that you shouldn't write them unless you need to, not that you shouldn't write them. He lists quite a few scenarios where they should be used, one of which is DSLs. :)
Also, given that Clojure is a lisp, I think you'll find you need macros left often than a language like elixir. They're still incredibly powerful, but you can do so much in Clojure without them that you would otherwise need a macro to do.
It's OK to be discouraging to a certain degree. It helps stop people from cooking up "clever" solutions.
Re:A few tips for writing macros in Clojure
by andrewingram on Sunday May 08, 2016 @09:01PM
(#11656902)
Well I try to use the right tool for the job, and it's important that code can be understood easily when it's read by other developers. But I think the 10 years with Lisp argument needs to be better justified. :)
Oh, I was not making a personal comment about you. It was a comment in your first point. That being discouraged by others is a sign that one should thread lightly. I was not discouraged by anyone when macros appeared on my horizon. And boy did I write some bad code. :)
Re:A few tips for writing macros in Clojure
by andrewingram on Sunday May 08, 2016 @09:29PM
(#11657000)
Makes sense :)
I guess i've just heard for so many years how badly wrong macro usage can go, that i've not even been tempted to try languages that use them - until very recently.
As long as it's not production code: You should actively seek out and learn/try as many things possible. Don't let anyone stop you. I once worked on adding a "maybe" keyword to python because boredom. It was a disaster. Fun though.
As an example, I've been using GraphQL quite heavily for the last 8 months, primarily with JavaScript and i've found it to be a fairly tedious experience. I tried out an Elixir GraphQL library that's heavily based on macros and was almost immediately more productive - despite not even knowing the language.
Similarly, coming up with a nice API for working with forms seems to be pretty much impossible with JavaScript. I've evaluated dozens, and not one comes close to the simplicity of Django's forms (which is only possible thanks to Python's metaclass magic).
Having sampled the power of languages with macros, I'm naturally drawn to Clojure, simply because it has a very decent JavaScript implementation. I'm sure there are other very good reasons for using the language, but right now macros are the motivation.
I'd like to understand why one would need 10 years of lisp experience before starting to author their own macros, it feels like a philosophy that's just going to stop people trying out lisp.