-
Per-project Postgres with asdf and direnv
My development computer typically has a number of different projects, each needing specific versions of some tools. Previously, I wrote about using
asdf
to manage my ruby, elixir, crystal and erlang version. I’ve been using it successfully to manage Postgres versions as well.What I get
- Precisely manage the Postgres version (e.g.
10.14
,12.5
) for each project. - The Postgres data directory lives alongside other project files
- No collision between projects. Each can have their own Postgres server running simultaneously.
- Precisely manage the Postgres version (e.g.
-
The REPL: Issue 82 - June 2021
EXPLAIN ANALYZE in PostgreSQL and how to interpret it
I’ve been working on web applications for a long time. From time to time I am called upon to figure out (and optimize) performance issues on some query.
EXPLAIN ANALYZE
lets you see what Postgres is doing under the hood. I don’t do this often enough to remember all the detail of what all the information returned means. This article explains the basics ofEXPLAIN ANALYZE
and links to some handy tools that help you focus on what matters.Do You Need Redis? PostgreSQL Does Queuing, Locking, & Pub/Sub
It’s no secret that I like Postgres a lot. This article explains some common use cases for Redis, and how Postgres can take care of them instead. It resonates with me, especially for smaller projects were the techniques outlined can avoid using another data store.
Stop worrying about PostgreSQL locks in your Rails migrations
To round off today’s Postgres love, this blog post introduces how the
safe-pg-migrations
gem can help when running migrations for databases with high-load and/or a lot of data. Traditionally, those operations can be problematic because of how Postgres acquires locks and can bring production sites down. The specifics are explained in detail in the post. Thesafe-pg-migrations
gem manages to turn what would be complicated steps to ensure safe migrations into the same exact semantics thatActiveRecord::Migration
uses.As soon as I tried this gem, I ran into an issue. The maintainer was very helpful. It turns out Ruby 3.0 support was pending. A few days later my issue was resolved.
-
Better Form Objects in Rails
ActiveModel
was introduced in Rails with the promise of being able to create model classes that interact well with the rest of the Rails ecosystem (e.g. routing, forms), but are not backed by a database table.It has some shortcomings, which are addressed by the
active_type
. Let’s look at an example. -
Book Review: Grokking Simplicity
Taming complex software with functional thinking
by Eric Normand
This book explores functional programming in a way that is very approachable for those starting out on that discipline, yet is still worthwhile for people that are already somewhat familiar with functional paradigms.
In Part 1, Normand explores the the difference between data, calculations and actions. Calculations are more traditionally called pure functions: They only depend on the inputs, and produce the same results when run multiple times. Actions are more traditionally called impure functions: The produce side-effects, and their results depend on where they were called. This key distinction is what the rest of the book is based on.
Part 2 explores functional abstractions for iteration,
map
,reduce
,filter
, and how to work with nested data structures. It then it goes on to derive several concurrency primitives and apply them. Concurrency analysis can be quite tricky, but was made very approachable by the use of timeline diagrams.Overall, I though this book was worth it. The examples where concise enough to understand, but not trivial. The code in the book is written in Javascript, a language a I don’t write or know very well: It was not a problem. In fact, it gave me an opportunity to reflect on what affordances Ruby provides that are very functional in nature.
I thought it was very neat that the author cautions the reader about the pitfalls of over-enthusiasm for newly acquired skills, and provides guidance on how to avoid it. There is also plenty of ideas on how to continue the functional journey. The last chapter even lists out what the author thinks the biggest takeaways are:
- There are often calculations hidden in your actions
- Higher-order functions can reach new heights of abstraction
- You can control the temporal semantics of your code
Links:
-
The REPL: Issue 81 - May 2021
Efficiency is the Enemy
There’s a good chance most of the problems in your life and work come down to insufficient slack. Here’s how slack works and why you need more of it.
The articles proposes that being very efficiently – constantly doing work – is not necessarily the same as being effective. Furthermore, being so busy can actually work against you, since you don’t have any spear capacity or slack to respond to new opportunities.
It reminded my of Technical Debt Is Like Tetris. In the tetris metaphor, playing the game – while you have room to maneuver – is enjoyable, calm, and allows you to setup the board to reap the maximum points (removing 4 rows at once). When your board is almost full and you don’t have any space, playing feels stressful, panic sets in, and each piece is placed without much consideration. Even if you manage to last a long time, you won’t be making big plays.
In a similar vein, How to Think: The Skill You’ve Never Been Taught – published by in the same website – talks about improving thinking skills by making time to think.