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.


2022 / Oct 11 — 15:44
kitallis

Here's a spectrum of componentizing views I've been thinking about lately (in Rails):

  1. Extract logical helpers and partials

They are often like stuffing away code inside a Module and calling it a refactor. But it is cheap and effective enough to start off with. You often run into "too many allocations" issues, with nested views and partials. They also don't abstract state very well. Arguments for their limitations have been made ad naseam - ex.

Completed 200 OK in 86ms (Views: 83.6ms | ActiveRecord: 1.3ms | Allocations: 29347)
  1. Presenter objects / ViewComponents

Solid ideas here. Fair bit of upfront work required and you have to be meticulous about the granularity of your components. These claim to be very fast by precompiling templates at rails boot.

  1. SPAs, building JSX components (or whatever else is out there now)

I'm not convinced I'd need to do this. I think Stimulus / Hotwired is powerful enough for all our needs for the forseeable future (famous last words). I still remember the joy of ripping out all the react from a previous codebase I worked on and rewrote them in a much simpler, basic markup and js.

#1 ➡ #2 hopefuly in a few months time.