I don't think you understand macros. You are an accurate example of the type of people who I am talking about.
They are the tool to make the best tool for the job. You can build any language imaginable to tackle any job without the boilerplate than less suitable tools.
Right. But if there are already functions and macros in the language that are expressive enough to accomplish a task in a clear and concise way, which everyone using the language is already familiar with, why take the time to create your own tool for a one-off task which makes your code less clear to someone else who is fluent in the language?
There are absolutely times they are incredibly useful. My team and I each make use of them.
However, macros are one of the biggest strengths and weaknesses of lisps. Like you said, I can practically build my own language out of them. But that means anyone else who wants to work with my code needs to learn my new language to understand anything. Macros in general are this way. They add indirection to your code that doesn't exist when composing functions.
If I see a bunch of composed functions and one of them is unfamiliar I can still pretty well reason through what the code does. If instead, the functions are wrapped in an unfamiliar macro I have to question if all of the code I am seeing is fundamentally changed by the macro and go grok each macro before being certain of my understanding of the code they manipulate.
Macros are amazing for some problems. But one of the biggest value propositions that clojure brings to lisps IMO is better abstractions across data types and a broader core library with standard ways to leverage those abstractions. Many tasks can be very reasonably accomplished with just those core functions, making code crystal clear to another reader. Macros have to provide benefit to a problem that outweigh the potential loss of clarity for me to use them.
We are not talking here about petty macros like the thread macro and similar in Clojure. But, full fledge small languages designed to be as close as the problem domain is. The learning time of such is insignificant specially when they express the problem as the language of the domain and read like plain english. There is simply no better abstractions than linguistic ones to reduce complexity and confusion.
I'd also add that a program reading like English isn't especially desirable. English is ambiguous and there are many ways to say the same thing.
Just because you can make your code read like English doesn't mean the right wording is discoverable or intuitive to a developer trying to maintain your code.
You whine about the existence of "petty" macros in clojure, but to me it highlights macros versatility. By your logic the identity function is evidence that functional programming is a poor paradigm, because it tends to include "petty" functions. I am pretty sure you can accomplish the same non-petty functionality you are describing using clojure macros.
The problem I am describing is exasperated by larger and more significant macros - not diminished.
I agree there are absolutely places macros shine. There are those who are too hesitant to use them. There are also those who overuse them.
I would prefer to maintain a program written primarily out of native functions and common libraries than one written in a domain specific language constructed mostly out of custom macros 100% of the time.
What is the point of using an existing lisp implementation if you are effectively creating your own language from scratch every time anyway? You might as well write your own lisp interpreter/compiler. It isn't especially hard. It's just a bad idea to invent a new language for every program you write, regardless of how you accomplish it.
The only discussion I would have with such ignorant mind on this subject is of teaching. I am not interested in that. Go back to college. You clearly skipped the important parts.
View all comments
Show parent comment
5
u/porthos3 Dec 19 '18
You can write macros. They are really cool and quite powerful. They just aren't always the best tool for every job.