Share options

Links to related pages

Make it sustainable. Keep it simple. Plan properly. Use the least power. Do it right the first time. Make intentions clear. Minimize cognitive footprint.

Code just in time

Time to read

, 385 words, 4th grade

As discussed in less is more, to avoid multiplying entities needlessly is not enough.

It is important to delay writing code until you are certain that you will need it. Even then, write it only at the last moment.

Never write a line of code until you have to.
Guillermo Rauch

Why? For at least two good reasons:

How many times have you written a piece of code only to toss it out, unused? How many times have you written code that you didnʼt immediately need? And then when the need arose, you found that code was obsolete and had to be rewritten?

If you are like most coders, then the answer is too many times.

But it is more than writing code that you may never use or writing it too soon. There is also premature optimization.

Suppose you know two or more ways to code something. If one of them has proven more optimal, then by all means write the code that way. See do it right the first time for more detail.

But, often, we have no idea where our bottlenecks will be before we write our code and test it. Optimizing code when you have no idea what the impact of that optimization will be is an exercise in futility. You may never need to optimize that code.

And if thatʼs the case, then optimizing it now will be a waste of time. Your time is better spent doing the right optimizations later: the ones that give you the most bang for the buck.

Premature optimization is the root of all evil.
Donald Knuth

You will save time by avoiding useless coding and premature optimization. That is time that you can then use to polish up your code and make it sparkle. Now weʼre talking Craft Code.

As Guille recommends: never write a line of code until you have to.

Code just in time.

Links to related pages

Make it sustainable. Keep it simple. Plan properly. Use the least power. Do it right the first time. Make intentions clear. Minimize cognitive footprint.

Get notified form

Get notified of site updates
Button bar

Carbon emissions for this page

Cleaner than 99% of pages tested
0.015g on first visit; then on return visits 0.007g
QR Code

Scan this code to open this page on another device.