Zero cost optimizations
Some optimizations come at virtually no cost. This can be in any area of life, not just in programming. Even if their benefit is limited, the cost is practically zero. So why not do them?
In this post I want to share some thoughts about the structure of this kind of optimization.
That sounds very abstract, so what do I mean by this?
One example would be accessibility. As a frontend developer you should know how to create accessible websites. I am not talking about the full-on-works-better-with-a-screenreader kind but just something that avoids the most common pitfalls. If you already know how to do it, why not do it all the time? It may not be a hard requirement in every project, but it sure is better than not doing it.
Another example is code styling. If there are agreed upon norms for writing code in a specific language, why not just use them?
One example from another area of life would be veganism. For the largest part it is healthier, kinder, and more sustainable than eating meat. There is no extra effort involved. I see no reason against it.
Obviously not all people value accessibility, code styling and veganism. I want to look at some common counter arguments:
You ain't gonna need it
YAGNI is a reminder against feature creep. Even if you think you will need a feature, don't implement it until you actually need it. I think this is valuable advice in many situations. However, all examples I mentioned were about doing a thing differently rather than adding something new on top. So I don't think it applies.
Effective altruism is a movement focussing on the optimizations with the highest impact. Their position is that you should not waste time and energy on low-impact optimizations if there are more effective things you could do instead.
This, again, is a very good point. The examples I mentioned all have high efficiency (high impact/cost ratio) but low effectiveness (low total impact). Still, I see no reason not to do them. I would rephrase this critizism as: "Don't spend time arguing about it, just do it". (I am aware of the irony of me writing a blog post about this topic. We all have our faults.)
Virtue signalling is the allegation that people do zero cost optimizations not for their benefits but to show off.
This argument can be reversed easily: People who do not do these little optimizations obviously just do it to show that they do not care. If you talk to someone about climate change and they order a steak, that is a statement.
Sure, I guess all these are signals. But that is mostly because "one cannot not communicate". I would argue that this form of communication is even useful in most cases. It is good to know whether the person I talk to actually knows and cares about the topic.
Habits and teams
When I say these optimizations come at zero cost, that is only true for the long term. When you are just starting you may need to change your habits, and changing habits is hard.
If you work with others you usually need to align your habits and expectations to a certain degree. If you only eat vegan food you will force this on anyone who invites you to dinner. The same is true if you insist on a specific code style during code review.
As you usually communicate with different people, you need to have some degree of flexibility in your habits. If you over-optimize, you will have a hard time fitting in.
Zero cost optimizations, also called "virtue signalling", are efficient but ineffective actions based on habits. Arguing about them is not worth the time. But doing them totally is.