Welcome to my PinkLetter. A short, weekly, technology-agnostic, and pink newsletter where we cultivate timeless skills about web development.
Should you write business logic in SQL?
No, of course not. Or at least, that’s what I thought for a long time.
SQL is less maintainable than non-SQL code. My ORM of choice makes things more composable. I cannot express imperative logic in declarative SQL.
Wrong, wrong, and wrong. I was so wrong.
Not only you can get all of the above, but also you cannot avoid writing business logic in SQL. Even the most straightforward query is an essential part of a use case.
I asked the wrong questions; thus I produced the wrong answers.
I fixed bad query results with nested loops in non-SQL languages. I wrote the code the ORM allowed me to, instead of the SQL I needed. I wrote lines and lines of imperative code that I could have saved with a couple of SQL tricks.
I ended up with the exact problems I was trying to avoid in the first place.
Stop asking if you should write business logic in SQL. Start asking:
What’s the best split between SQL and non-SQL in the current context?
Running Out of Maps by Joël Quenneville
Many Elm packages provide map2, map3, map4, etc functions. No matter how many of these the package author has provided, inevitably someone will end up needing a mapN larger than those included in the package. Perhaps that “someone” is you. How do you deal with a situation where you run out of maps?
(Riccardo: Applicative functors in Elm FTW.)
The Art Of PostgreSQL by Dimitri Fontaine
Applications nowadays are written with the help of many programming languages. When the backend should implement user oriented workflows, it may rely on a RDBMS component to take care of the system’s integrity.
In this talk, we learn advanced SQL techniques and how to reason about which part of the backend code should be done in the database, and which part of the backend code is better written as an SQL query.
(Riccardo: This is a treasure trove of SQL wisdom.)
The Stubborn Optimist’s Guide Revisited by Center For Humane Technology
Internationally-recognized global leader on climate change Christiana Figueres argues that the battle against global threats like climate change begins in our own heads. She became the United Nations’ top climate official after she watched the 2009 Copenhagen climate summit collapse “in blood, in screams, in tears.”
In the wake of that debacle, Christiana began performing an act of emotional Aikido on herself, her team, and eventually delegates from 196 nations. She called it “stubborn optimism.” It requires a clear and alluring vision of a future that can supplant the dystopian and discouraging vision of what will happen if the world fails to act.
It was stubborn optimism, she says, that convinced those nations to sign the first global climate framework, the Paris Agreement. In this episode, we explore how a similar shift in Silicon Valley’s vision could lead three billion people to take action for the planet.
(Riccardo: The Center For Humane Technology is killing it episode after episode. You should give the podcast a try, or watch The Social Dilemma on Netflix.)