Short notes from engineering

Micro-posts on programming and patterns as we build Tramline in public. Follow this feed if you find these bits interesting.


2023 / Aug 08 — 19:41
kitallis

then in Ruby feels like a little sister to the as-> macro from Clojure.

Most of the API code (and several other parts) in Tramline make heavy use of then.

example, example, example.

There's a couple of interesting things of note here.

One, I think numbered params have a lot of scope in removing some of the block cruft and overnaming of things across then blocks. Especially if the next in chain is visually obvious.

@client.workflows(repo)
       .then { fetch_workflows(_1) }
       .then { pick_active(_1) }
       .then { transform_keys(_1) }

The above feels more natural and less noisy than naming each intermediate step with similar sounding variable names.

The second one is a controversial (perhaps even wrong) point. It seems to me that since then is just a function, the general debuggability of something going wrong in the pipeline is easier to find out in the chain.

My (now fading) experience with threading macro debuggability in Clojure has been less efficient; I end up adding taps and spies and macroexpands to figure out what part of the chain broke.

I prefer an experience like:

  1. write a pipeline
  2. pipeline breaks in expression number 2
  3. error output nudges you in the direction of just tweaking expression number 2
  4. make the fix and the pipeline starts working again