Hajime, the duck guy

Monday, March 18, 2024, by Hajime Yamasaki Vukelic

Is all the choice killing you?

How do you make the right choice?

When you start programming (and ever since), you are faced with choices. You have more than one way to accomplish something, more than one syntax for saying the same thing, etc. Choices are inevitable, and in most cases there's no one size fits all answer. You have to cultivate the flexibility to pick the optimal path, preferably on short notice.

Meaningful vs meaningless choices

Identify the type of choice: meaningful or meaningless. For meaningful choices, make a rational one. Luckily, there's only one right choice. For meaningless choices... it's more like religion. Meaningless choices are best made ahead of time. Try them all, and pick the one you like. Or just pick a random one. And don't spend time making it every time. They are mostly meaningless anyway.

Meaningful choices

Meaningful choices are usually related to trade-offs and/or use cases. One choice was created for one use case, and optimized for it. Another option was created for a different use case. There is no other choice but to find out exactly what each option does, and which is more appropriate.

Another kind of meaningful choice is legacy versus new. In many popular libraries, you have APIs that are legacy and deprecated, and you have APIs that are intended to replace them. Here, the choice is to simply go with the later version. The deprecated API will eventually be removed, regardless of how much better or worse it is.

Hidden meaningful choices

Some choices are meaningful but not well-documented. For instance, a choice between a module-level function declaration and an arrow function can have tangible performance impact, even though they appear to be a cosmetic choice. Sadly, you usually find out about these things the hard way...

Meaningless choices

Meaningless choices are mostly cosmetic/religious. Something gets added because a vocal group of people wanted something to work differently. This is especially true of platforms that need to have 100% backward compatibility (e.g., JavaScript). The choice basically boils down to preference. For example, XMLHttpRequest vs fetch(), chaining .then() vs async/await. In a team setting, it may not necessarily be your preference, but it's still someone's preference. Although there are some advantages to using one over the other even in these cases, it's not a tangible/critical advantage such as the difference between using a for loop versus array methods. Again, I suggest you strive to make these choices in advance, so you don't end up wasting time on things that ultimately don't matter.

Don't be deceived by the date of manufacture on a feature. Things that are new aren't necessarily replacing older things, even though they may look similar. For example, the for loop has features that array methods don't. Some array methods copy the array while others don't (usually the older ones), even when they seem to be doing the exact same thing. And so on. These are all meaningful choices.

Posted in Opinion
Back to top