It’s commonly agreed [citation needed] that declarative programming is better than imperative, since it hides irrelevant details from the programmer. This makes the code more compact, focused, and with less noise. Commonly, we care more about the “what” than the “how”. Still, most programming languages out there are not declarative in nature. Why?
You can argue that a good code-base would construct an embedded domain-specific language which is mostly declarative. In a sense, each function you write hides irrelevant details from the calling context.
You can also argue that being declarative is easier in a small domain, like SQL in database processing. Most programming languages are general-purpose, so it’s up to the programmer to construct his/her own declarative primitives, as noted above.
Is this what happens, though?
As a web developer I do of course REST APIs, and there’s no obvious reason why a REST API shouldn’t be 80-90% declarative, as a data mapping between an internal and external representation. Still I have to sit and worry about dependency injection (a clear “how” rather than “what”) and god knows what. At least on a personal level I’m failing at the “build declarative primitives” task.
I’d like to propose the possible solution that an external, rather than embedded, DSL could help. There are a couple of counter-arguments to this solution that one always hears:
-
An in-house DSL can’t be debugged as easily, and won’t have support from IDE
-
You’ll end up with a bad implementation of Lisp in the end.
-
On-boarding cost will increase.
-
Bus-factor will increase.
I have a growing feeling that accepting these arguments without further discussion can reduce programmers to cogs-in-the-machine. Also feels a bit like marketing jumbo from Java enterprise beans…
I also propose that S-expressions and Forth-like languages can be a basis of a family of external DSLs for different use-cases, languages easy enough to spin up in 100 LoC.
“Just use Lisp/Scheme/Racket” is not a valid counter-argument, because most of us are career-locked in other languages.