Blogs were/are a fun moment
Manuel Moreale, Why I write:
But the reason why I started is long gone at this point. I started the blog as some sort of public accountability tool and it’s now everything but that. I don’t write to be accountable. I probably should.
Manuel asks a lot of folks about why they started writing their blogs. It’s a great question! Some folks want to get weird, others can’t not write and putting it online as good as anything, still others want to connect with a community.
That last one, connecting with a community, is closest to my answer. I started because there was so much excitement, energy, and connection in the early 2000s blogs. It was a real scene. And, plenty of invention! Before there was centralized social media and web 2.0 there was decentralized blogging. An earnest attempt to take the technology of peer-to-peer file sharing and build something besides music sharing on it. It was a fun moment.
Avoid the ternary operator, I’m begging you
Allow me a bit of a soapbox-rant. A spicy take, as we might say these days.
You’re using the ternary operator wrong in Ruby, JavaScript, and almost everything else. It’s for expressions, not control flow.
My personal ternary journey of discovery, delight, and distaste:
- In the old C days: what is this noise? What does a colon even mean in this language? Is this even syntactically valid?
- Later, in verbose languages like Java: oh I get it, let me show off by using it. I like that I can compress five simple lines of conditional down to one.
- Currently, seeing how it’s used in shell and React code: actually this is awful let’s never use this. Delineating the arms of a conditional with one character is awful for scanning and discovery code.
- Even when it’s appropriate, I feel a little bad.
The nuanced take: a one-condition ternary with no more than 4 tokens is maybe okay. If I can’t fit my ternary expression in 80 characters, switch to an if/else conditional. (It’s not that bad!)
// fine, I guess
foo = bar ? baz : quux
// stop this, I'm begging you
msg = bar ? ...dozens of lines of code
: ...dozens more lines of code
Why I try to avoid it:
- in the year 2024, your editor can write conditionals for you
- some folks can’t even keep your ternaries at 10 tokens, let alone 5
- and it’s literally showing
- hence, I’m here writing about it
- the ternary operator is not for control flow, stop that
- the ternary operator is really only suitable for assigning values based on other values
- for example, in the expression
val = foo ? bar : baz valdepends onfoo- the ternary operator is a good way to represent dependency/correlation!
- for example, in the expression
- I don’t care what React’s conventions are anymore
- they’re not good in this regard
- use conditionals for control flow
- use variables to assign meaningful names to big chunks of markup
- please, stop with the boolean and ternary logic
- I’m literally writing this before the sun rises, asking you to stop
- the ternary operator is really only suitable for assigning values based on other values
- ternaries don’t airlift/refactor well
- you can’t pluck one bit of code out of a ternary and drop it somewhere else
- I feel this one in my bones but can’t think of a short example
- (citation needed)
Bonus track: stop adding conditional clauses!
// fine
if safe-to-release
launch-the-missiles
else
reset-to-ready
end
// bad, you got some refactoring to do
if safe-to-release && target-acquired && something-that-seemed-right-once && tuesday || national-holiday
...
end
I’m guilty of this temptation to add “just one more conditional!” I regret it.
It makes code difficult to reason about. It’s basically impossible to tell people when the thing will happen in the “bad” example.
If you manage to get something right in multiple conditions today, you’re probably only making it harder for yourself (or someone else) tomorrow.
I will support you 90% of the time if you want to take 30 extra minutes to turn a multi-clause condition into a simpler structure. Your teammates will hail you as a hero later when they need to read or modify said simpler structure!
A disproportionate percentage of bugs hide in conditionals. If they’re easier to read and change, hopefully we’ll write fewer bugs!
Psuedoprose
Taylor Troesh’s pseudoprose is a notation for writing/note-taking/thinking:
How to
- Write in English, Spanish, whatever.
- Grammar is optional.
- Markdown is encouraged.
- Embed in any document with [[…]] brackets.
- Use {…} for comments.
- Use <<…>> for LLM instructions.
- “tk” means “todo”.
Why
- Jot down notes/ideas quickly.
- Focus on semantics over syntax.
- Less text to edit.
- Offload grunt work to LLMS.
Notably, also a notation for annotating LLM/AI/Copilot interactions directly into your text. For the wonks, a GPT-4 prompt is included to convert psuedoprose to well-formed Markdown without any code. What a world.
Other folks’ ways of writing and taking notes are endlessly fascinating.
Rails generators are underrated
Every experienced Rails developer should pick up Garrett Dimon’s Frictionless Generators. Generators are an often overlooked piece of the Rails puzzle. The book shines a light on getting the most out of generators in your Rails projects. It’s an amazing-looking digital object too, the illustrations are great.
(Before I go further, it’s worth noting that Garrett Dimon sent me a review copy, acted on my feedback, and is generally a pal.)
You should customize generators and write your own
Conventions, in the form of assumptions that are woven into the framework’s code but also exist as a contract of sorts, are essential to Rails. Following those conventions would not work well if creating a new model, resource, etc. wasn’t made easy and consistent without our friends rails generate resource/model/etc. These generators have been present in Rails since the beginning. I’ve used them hundreds of times and thought nothing of it.
A few years ago, I realized that generators had become a public API in Rails and that re-use was encouraged. The guide is a good start. I was able to knock out a simple generator for a novel, but conventional, part of our application. In the process, I realized a couple of things.
No one likes boilerplate and tedium. Generators automate the tedium of boilerplate. This is particularly helpful to less experienced developers, who are likely a bit overwhelmed with trying to comprehend decades of Rails evolution and legacy code (from their perspective) quickly.
Rails developers are under-utilizing this leverage. Every system that makes it past a few thousand lines of code (or several months in use) develops bespoke conventions. These are easier to follow if you can reduce the mental burden to “when you add a new thingy, run rails g thingy”. Added bonus: starting new conceptual pieces in your app from generators encourages consistency, itself an under-appreciated sustaining element in long-lived Rails applications.
Luckily, someone was thinking the same thing I was…
Garrett knows more about generators than anyone I know
The Rails guides for generators are okay. They whet the curiosity and appetite. But, they aren’t particularly deep. When I first tinkered with generators, I mostly learned by reading the code for rails generate model/resource/etc.
Frictionless Generators does not require one to jump right into reading code. It opens with ideas on the possibilities of developing with custom generators. Then, it moves onto the practicalities of writing one’s own generator and crafting a good developer experience. From there, it’s down the rabbit hole: learning about the APIs for defining generators, implementing the file-creation logic therein, writing help and documentation for them, generating files from templates, and customizing the built-in Rails generators.
Garrett goes into as much depth on generators as any other technical author I know, on any topic. Did you know you can make HTTP requests and use their responses in generators? I did not, but Garrett does! Did you know that generators apply the same kind of “oh, yeah, that’s common sense” convention for copying files from generators into applications? I did not, but Garrett does! I don’t think I’d use all these ideas on every generator, but I like the idea that I can return to Frictionless Generators should I have an idea and wonder how the existing, low-friction APIs can help me.
Further, Garrett offers frequent insights into the developer experience and leverage of building generators. On building generators for “fingertip feeling” so developers can easily (and frequently!) use them:
I like to aim for no more than one value argument and one collection argument to keep generators easier to use. Everything else becomes an option.
On approaching generators as high-leverage side-quests:
Remember that the ease of use is generally inversely proportional to the length of your documentation. Assistance first. Brevity second. Content third. Or, be helpful first, concise second, and thorough third. That said, there are a few other categories of information that can be helpful.
For me, a good technical book balances presentation of technical information, the right amount of detail, and wisdom on how to apply the two in practical ways. Garrett succeeds at striking that balance while keeping things moving and easy to follow.
In short, recommended! Rails generators are underrated, whether you’re aware of their existence or not. Smart teams are customizing generators and writing their own bespoke generators. There’s a book on this now, which you should check out if any of this resonated.
Collective flow
Dave Rupert, Play at work:
I’ve talked about this before in the context of prototyping and play and how we worked at Paravel. It’s a lot like playing baseball; each member of the team showing up to practice, volleying work (in screenshots, short videos, or demos), pushing changes, communicating thoughts and challenges in the moment outside the confines of slotted meeting times. Me and my coworkers, having a catch.
Several years ago, when I was doing improv, I was rehearsing for a musical, of all things. At the same time we were getting started with table reads and gel’ing as a cast, two other shows were rehearsing in the same theater. One show was about to open, very much having their thing dialed in. Another cast was somewhere in the middle, having figured out what they were about but still trying to get the execution just right. Everywhere in the theatre, there was creation and exploration energy and it was one of the most awesome things I’ve done. This despite not liking musical theater much!
I don’t like the idea of “return to office” and I don’t think you could make it work anyway. The social momentum that kept a critical mass of people in one office has been broken, you can’t put that toothpaste back in the tube.
That said, I have yet to feel that same energy in remote work that I did in a local theatre on rehearsal night while various groups were making something together, in the moment, and iterating on it as quickly as they could share a glance or read through a scene.
I bet some teams have figured out how to feel this way in remote/async setups. But, it feels like most are still running the old in-person playbook that we learned, and sometimes thrived with, over the past years and decades of our careers.
“Yes, and” despite pessimistic engineering intuitions
As engineers, we often face the consequences of shallow ideas embraced exuberantly. Despite those experiences, we should try to solve future problems instead of re-litigating problems-past.
Engineers put too much value on their ability to spot flaws in ideas. It’s only worth something in certain situations.
— Thorsten Ball, 63 Unpopular Opinions
Don’t be edge-case Eddie, wont-scale Walter, legacy code Lonnie, or reasons Reggie. At least try to think around those issues and solve the problem.
This is very much a note to my previous self(s).
Pay attention to intuitive negative emotion…If you’ve been asked for quick estimates a bunch, you might have noticed that sometimes the request triggers negative emotions: fear, anxiety, confusion, etc. You get that sinking feeling in the pit of your stomach. “Oh crap”, you think, “this is not going to be easy.” For me (and most experienced software engineers), there are certain kinds of projects that trigger this feeling. We’re still pattern matching, but now we’re noticing a certain kind of project that resists estimation, or a kind of project that is likely to go poorly.
– Jacob Kaplan-Moss, The art of the SWAG
Jacob recommends noting how intuition and emotion are natural and not entirely negative influences on the process of evaluating ideas. The trick, he says, is to pause and switch to deeply thinking through the idea (or estimate) you’re presented with.
This, again, is very much a note to my previous self(s).
Now, if you’ll excuse me, I need to get back to brainstorming and estimating this time machine, so I can deliver this advice to my former self.
You learn faster by falling down
Julia Galef, The Scout Mindset:
The “self-belief” model of motivation assumes that if you acknowledge the possibility of failure, then you’ll be too demoralized or afraid to take risks. In that model, people who believe that failure is unthinkable are the ones who try the hardest to succeed. Yet in practice, things often seem to work the other way around—accepting the possibility of failure in advance is liberating. It makes you bold, not timid. It’s what gives you the courage to take the risks required to achieve something big.
One of the most impactful ways I’ve adapted my thinking over the years, if only modestly successfully, has been to fear failure less and accept small downsides more easily. There’s way more world out there for those willing to trip or even fall now and then.
Building software is great
…even if some days working in corporations or under unwanted pressure makes it considerably less fun.
I also just don’t especially want to stop thinking about code. I don’t want to stop writing sentences in my own voice. I get a lot of joy from craft. It’s not a universal attitude toward work – from what I can tell, Gen Z is much more anti-work and ready to automate away their jobs – but I’ve always been thankful that programming is a craft that pays a good living wage. I’d be a luthier, photographer, or, who knows, if those jobs were as viable and available. But programming lets you write and think all day. Writing, both code and prose, for me, is both an end product and an end in itself. I don’t want to automate away the things that give me joy.
– Tom MacWright, The One About AI
What a great distillation of what makes working on software great! It’s an opportunity to think all day, earning a good wage doing so. Sometimes, to make something of value. Even more rarely, to make something of lasting value. Most of all, to be challenged every day. On the good days, it’s the future we were promised!
Use fewer algorithmic feeds, mostly search-based
Rob Walker via Austin Kleon, More search, less feed:
I’ve been thinking a lot about the search box versus the feed,” he said. “Let’s take Twitter. When I open it, everybody wants me to think about something.
A Ponzi ecosystem of hustle, reality distortion and projection, outright misinformation and propaganda. Plus, folks who just want to tell you the world is miserable. On the other hand, some funny takes and the occasional wholesome content. As goes social media, so goes humanity.
That bit of (attempted) gallows humor aside, the linked article has a good angle: search for more information and do actual research rather than letting algorithmic-people filter it towards you. Caveat: this may have been more useful when that post was written in 2019 than it is in the reality of junky internet search that is 2024.
Reminder: think your own thoughts.
Shell history is more valuable than shell customization
Thorsten Ball, Which command did you run 1731 days ago?:
Recipe for living a good life in the shell:
- Make sure it’s fast.
- Make sure its history can grow nearly infinitely and you can fuzzy-search through it.
A sage developer once told me he didn’t maintain dotfiles at all. He worked across so many machines and servers that keeping a shell configuration working across many systems was folly. Instead, the most important thing for him was making sure his shell history was synced across all those computers.
At first, I thought this was merely amusing. But the more I thought about it, the more I realized how deeply wise it is. Dotfiles, in the form of functions and aliases, abstract and ossify, the commands you think you’ll run frequently. But reverse searching through your total shell history provides you with access to commands you have run and lets you quickly edit/adapt them in-situ.
This makes the history file for your shell (possibly) the most significant file on your computer. Not just because it’s useful, but as a working memory and a reflection of your journey.