Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- Yes!
Declarative code has low cyclomatic complexity per unit of business logic. It also tends to have low state management demands (which the functional devotees will tell you is the root of all evil).
You can use a DSL or other abstraction so that you can declare what will happen in what circumstances, in a way that’s succinct and easily comprehensible. And all the repeatable loops and conditionals that make the declared thing happen in the appropriate circumstances are under the hood and needn’t be concern or be loaded into mental context by the person designing or updating the requirements.
It’s not the right solution to every problem, but when you can apply it effectively it’s a huge win.
However, agents and most SWEs are trained on imperative (wrapped in procedural/functional/OOP paradigms), and most will default to imperative because it’s familiar.
As I get deeper in my career I find myself gravitating toward a style that’s declarative where possible, falling back on functional, and then only when necessary imperative/procedural/OOP. It’s nice that many modern languages allow you to mix and match features of all those paradigms.
TL;DR: Mental load is the bane of programmers everywhere, and declarative programming minimizes mental load.
by apothegm - Perhaps you may find like-minded folks in the functional-thinking community:
I was trying to figure out what you meant by "declarative" because CSS is declarative. (My understanding is: "declarative means you say (declare) what you want, but not how to get it." Usually SQL is the poster child of declarative languages.)
I think you're really talking about a mix of preferring data (vs actions/calculations) and DSLs (which aren't necessarily declarative)
Eric Normand has some thoughts you might appreciate:
- How a problem might take 1000 SLOC to solve directly, but only 10 SLOC with a DSL (plus up to 500 SLOC for the DSL itself; still fewer lines total) https://ericnormand.me/podcast/magical-leverage-languages
- Data vs calculations vs actions: https://ericnormand.me/podcast/what-is-an-action
---
I think data can be very powerful. For example, someone explained to me:
> I've been helping my non-tech father with Home Assistant. I've honestly been shocked with how far "community extensions" + "user configuration" can take you. Every time we hit a bug, I go "time to hit github" but without fail chatgpt and him are able to tweak a setting to get it working.
If you make your system configurable (config==data), you can skip the whole compile/build step!
by Leftium - Metamine was a language that appeared here on HN a few times, but seems to have disappeared. The thing that made it interesting is that it let you mix imperative and declarative code in the same program. It did this with a "magical equals", after executing it once, the left side auto-updated outside the flow of the imperative code.
The demo was pretty fun to watch.[1]= magical equals, which maintains the relation for the rest of the runtime note: once you use it on a variable, you can't redefine it later, that's an error := normal assignment, which only fires once[1] http://web.archive.org/web/20201014024057/https://www.youtub...
by mikewarot