I was asked about why declarative programming is at the heart of "newer" trends in tech all the way up and down the stack, from React to Terraform.
I replied in an email but here it is as a quick thread:
DOM APIs are imperative, which encourages manual setup/teardown of event listeners, and intermingling of business and presentation logic.
At best this is just quite verbose and disorganized, at worst this creates runtime bugs and memory leaks. Lack of structure is painful.
We use React/Vue/Svelte to organize code into declarative components, help us organize the above and automate the boring parts. It also lets us *share code* much easier because the markup, state, and styles are scoped to the component, so they don't leak to the rest of the app.
This then lets us share reusable component libraries, which helps create a more productive ecosystem.
a key schism in approach to declarativeness is the concept of templates - React is against it, Vue and Svelte are for it.
) for faster rendering, and Svelte to do fast serverside rendering. React understands this, chooses not to be declarative here, because it would involve custom syntax. React prefers to stick to "just Javascript".
another difference is what the reactivity declaration inside components are like. React errs on the side of rerendering all variables by default, prioritizing correctness and early bug discovery over performance. You optimize by declaring idempotence (eg with useMemo/useCallback)
Svelte errs on the side of not recalculating by default, prioritizing simplicity/performance over some intuitiveness (aka theres a learning curve). You selectively make things reactive by using the `$:` label .
projects like Terraform and Pulumi and AWS Cloudformation/CDK are the backend equivalent - "Infrastructure as Code" eliminates error prone manual setup ("clickops").
The "as Code" part is somewhat in flux, as IaC is in the midst of a swing back to imperative.
Anyway, IaC helps you treat your infrastructure like "cattle, not pets", making it easier to reason about because you always start from a clean slate, and its easier to spin up the same resources for testing, or to deploy to another region for scaling needs.
Declarative is NOT automatically "better".
Declarative is higher level (concise, correct, leaky), Imperative is lower level (fast, efficient, powerful).
People always want more power in declarative formats, adding ifs, loops, and vars, ending up with: beza1e1.tuxen.de/articles/accid…
Eventually declarative gets unreadable/slow and we swing back to imperative + General Purpose Languages for more control
Ultimately I think we swing between declarative and imperative every time we go up another layer of the software stack:
We often get caught up in other people's games. Ladders, likes, follows, points. Winning can bring a short-term rush, but feel empty after. These games are traps for competitive, ambitious people.
The primary beneficiary of you being #1 on Product Hunt is Product Hunt.
The primary beneficiary of you being Employee of the Month is your Employer.
The primary beneficiary of you going viral on Twitter is Twitter.
Youre surprised *everything* around you is designed this way?
- Zero sum
- Finite game
- Single number
- Regular schedule
- Costs them nothing
- Rules clearly stated
- Winner irrelevant in 1 year
- Timing matters
- Microcopy matters
- Social proof matters
The Handbook: 450+ pages of everything I have learned about building an exceptional and *sustainable* coding career. This is the ultimate guide for the 4-8yrs from Junior to Senior Dev!
). We get so much more out of it when we can *talk* to fellow readers!
I stepped down from my active /r/reactjs moderator role and will be personally moderating this new @discord!
The Creators: For those who want to peek #BehindTheScenes, I have put up 2+ hours of Author's commentary and 10 hours of recorded writing sessions to show you how @Coding_Career was put together.
I'm also doing some Workshops (to be recorded) where you can ask me anything live!
I've been mainlining the entire back catalog of Screaming in the Cloud and AWS Morning Brief to get smart on things. Corey packs a lot of snark but gives credit where due and makes topics accessible to beginners!
Help them put you in an expensive, high-sentimental-value, glittering, easy to reach box. Preferably at eye level, near Checkout, next to other nice looking boxes.
You don't have to market to the whole world.
You can target specifically the audiences you want to work for, and no more.
As long as you are well-known in those circles, you don't need a public presence at all.
A lesser book would stop here - mostly explaining factual statements in a more accessible way than the official docs, and then ending with some advice.
That's fine and a fair deal for many technical books.