Welcome to 20XX
We're back. I actually wrote half of a year-end bonus Skill Issue, but decided that I'd rather spend more time surfing than finish. We're back now, though.
The Value of Objects
I'm always looking for ways to improve Solidus. My work on Solidus benefits all of Super Good's clients. In biz speak, it's high-leverage. When I encounter a pain point, or notice that a bunch of our developers have hit the same issue, I try to open an issue and think about how we might better address it.
It's trickier with onboarding pain points. You only install Solidus once per project. You're usually trying to get momentum going and unlikely to switch gears to make improvements to the platform. You're focused on showing progress to the client or stakeholders. Reducing onboarding friction is super important to attracting people to the platform, though.
Yesterday we added a temporary workaround to the Solidus Starter Frontend install instructions to address an upstream issue with Sprockets. Not exciting stuff, but we know people have stumbled there.
Another thing that I'd love to address is the use of hashes instead of objects for passing data around. See this:
def self.price_filter
value = Spree::Price.arel_table
conds = [[I18n.t('spree.under_price', price: format_price(10)), value[:amount].lteq(10)],
["#{format_price(10)} - #{format_price(15)}", value[:amount].between(10..15)],
["#{format_price(15)} - #{format_price(18)}", value[:amount].between(15..18)],
["#{format_price(18)} - #{format_price(20)}", value[:amount].between(18..20)],
[I18n.t('spree.or_over_price', price: format_price(20)), value[:amount].gteq(20)]]
{
name: I18n.t('spree.price_range'),
scope: :price_range_any,
conds: Hash[*conds.flatten],
labels: conds.map { |key, _value| [key, key] }
}
end
Don't worry about all that format_price shit. This method returns a hash with specified keys. There are other methods like this one in the same file which return hashes with the same structure.
These aren't even consumed in this codebase. It's the starter frontend that uses this module. We've created a cross-project dependency that involves passing arbitrary hashes around. I hate it.
Luckily, this module is meant as an example. You're meant to copy it in and modify it. The obvious first modification you should do looks like:
ProductFilter = Data.define(
:name,
:scope,
:conditions,
:labels
)
From there, you can modify the methods to return instances of ProductFilter and easily update your consuming code to operate on these normal Ruby objects. I did it to a project yesterday and it only took a few minutes.
There's lots of reasons why this is better, but there's one I always point to. I wrote about it in Structure and Purpose. Matching the structure of your code to its purpose makes it easier to understand.
99% of hash operates aren't applicable to this return value. If the value is meant to be used a static data container, make it a damn static container.
Oh, I guess I'm the one expected to fix this upstream, eh?
Death From Algorithm W 1979
While I was out for the holidays, we dropped an episode with Sabine Schmaltz. I'll take any excuse to talk about OCaml, and this was a pretty good one.
I've seen various claims that one language or another is "better" for heavy LLM-based development. I'm not bought in on that idea, but I was curious to hear about her efforts to vibe code a project in OCaml, a language that isn't really part of that conversation.
I also enjoyed catching up on the state of the OCaml ecosystem, her thoughts on how organizations can approach adopting OCaml, and what we can look forward to in that space.
The Protomen – Act III: This City Made Us
In 2005, The Protomen dropped their debut album, a self-titled rock opera set in the Mega Man universe. I discovered it through a friend in 2006.
It stands alone as the album that I have listen to front-to-back the most times. I don't have a count, but it's inconceivable that any album will ever surpass it in that regard. I can't begin to explain how much I love that record.
Fast forward to 2009. The economy is in turmoil. People are taking to the streets in Iran. The United States is waging a war under false pretences. The Protomen release Act II, a prequel to their first album. I love it, but it leaves me even more curious about how Dr. Light's story will end.
It's 2026. Seventeen years have passed. The economy is in turmoil. People are taking to the streets in Iran. At least the US is admitting their new war is just about oil.
Oh, and Act III is here. It doesn't disappoint.