Jun 21, 2019

Choose What Allows You to Proceed Now, Optimize Later

One of the advice that get thrown around in programming is “premature optimization is the root of all evil.”

It is usually illustrated by horror story where someone decide to write their code in an awkward manner with the intention that it would make the code faster, but after long time later when they eventually do a performance measurement they found out that what they did actually make the code slower.

If you want to optimize a piece of code, always make measurement before and after your optimization, else you wouldn’t know what you do is actually help or harm the performance.

However, that doesn’t mean that you shouldn’t worry about code performance at all. Instead, feel free to write code that you assume would be more performant as long as your code is still idiomatic, e.g. Promise.all, use object instead of array for data that you will lookup very frequently.

In other words, you can assume performance, but prioritize on writing idiomatic code, because idiomatic code is easy to change or optimized later.

This tips actually doesn’t apply to writing code only, but to how we decide what we do in life as well.

  • How do you know taking that job is a good fit, or wait for a better one?
  • How do you know what professions that you would enjoy the most?
  • How do you know what kind of people that you like to spend time with?

Your parents would’t know, your self-help guru wouldn’t know, you wouldn’t know.

As long as the decision is easy to be changed later, do what allows you to proceed at the moment, and optimize later.

Thanks for reading!

Love what you're reading? Sign up for my newsletter and stay up-to-date with my latest contents and projects.

    I won't send you spam or use it for other purposes.

    Unsubscribe at any time.