swyx Profile picture
25 Oct, 12 tweets, 3 min read
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.

(arguably more templating is more declarative.)
this allows Vue to make optimizations () 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:
🤦‍♂️ In my eagerness to explore details, I forgot to say the thing EVERYONE says:

You mostly don't care about the HOW, so just specifying the WHAT is better. This lets us do *crazy* optimizations.. if we accept the black box.

This is fine - until it's not.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with swyx

swyx Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @swyx

18 Jul
Resharing advice I gave to a friend:

**Don't play games you don't want to win.**

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?
"Play stupid games, win stupid prizes." - @naval

Characteristics of stupid games:

- 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
Read 5 tweets
10 Jul
💁‍♂️ How to Play Long Term Games:

Systems > Goals
Discipline > Motivation
Trust > Distrust
Principles > Tactics
Writing > Reading
Vulnerability > Confidence
North Stars > Low Hanging Fruit
Trends > News
Habits > Sprints
Questions > Answers
Problems > Solutions
People > Projects
Listening > Arguing
Empathy > Enmity
Values > Metrics
Actions > Reactions
Health > Wealth
Forgiveness > Revenge
Automation > Decision
Delegation > Control
Growth > Fixed mindset
"Yes, and" > "Well, actually"
Community > Solo effort
Identity > Outcomes
Science > Social Science
Integrity > Capability (h/t @chamath)
Designing > Forecasting
History > Geography
Micro > Macro econ.
Resilience > Perfection
Redundancy > Efficiency
Lasting > Winning
Wisdom > Intelligence
Drive > Inspiration
Investing > Spending
Proactive > Reactive
Data Structures > Algorithms
Read 6 tweets
1 Jul
🚨 The @Coding_Career Handbook is here! 🚨

It comes in 3 flavors.

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!

learninpublic.org/?from=Twitter%…
The Community: Every book should have a community section (). 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!
Read 14 tweets
29 May
👋 Personal update: I've joined @AWScloud!

Here's how I think about @AWSAmplify, and why I joined: swyx.io/writing/hello-…

There is so much I don't yet know and I'm excited to #LearnAWSinPublic. 🥳 Got any advice/resources? I'll share some I've found below 👇
3 Big Things I Wish Someone had Told Me When I Started Using AWS

I found @jaredshort via @jeremy_daly's awesome Serverless chats podcasts. Both of them share a great deal of hard earned AWS knowledge!

dev.to/trek10inc/3-bi…
All of @QuinnyPig's AWS media empire: lastweekinaws.com

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!
Read 13 tweets
13 Apr
✍️How to Market Yourself (without Being a Celebrity):

swyx.io/writing/market…
People want to put you in a box.

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.
Read 32 tweets
7 Apr
✍️5 Things I Learned from The DynamoDB Book

Alright folks, I had the chance to review @alexbdebrie's incredible new book on @dynamodb

swyx.io/writing/dynamo…

Time for one of my Epic Book Reviews™!

Thread form below:👇
You can roughly group the book in 4 parts.

Chapters 1-6 (~120 pages) - Explaining DynamoDB Concepts, APIs, and Expressions

it's dynamodbguide.com expanded!

Chapters 7-9 (~50 pages): Advice for DynamoDB Data Modeling/Implementation

Preview:
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.

But this book *keeps going*.
Read 11 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!