[go: up one dir, main page]

DEV Community

Cover image for Paired down programming
Ross Angus
Ross Angus

Posted on • Edited on

Paired down programming

How many bytes does a character take up?

My colleague Nick asked me this question because he wanted the JavaScript in his tiny Solar system to be under 1k in size. We never bothered finding out the answer, but instead both stared at the minified code, looking for ways to save a few characters.

Unwittingly, I think Nick created a pretty good recruitment tool: show a candidate some code and pair-program ways to shrink it down. It won't lead to the most maintainable code, or the best practice, but it should give you an idea of how that candidate's mind works.

Pretty soon, I found myself saying stuff I had no business poking my nose into, such as could that be an arrow function? Just to be clear, I regard arrow functions as a form of street-slang and witnessing a man of my advanced age using them would be about as elegant as watching me beatboxing. Turns out I was right, though: we saved a few bytes by converting one function into an arrow function. Nick went through the rest of the code, but it wasn't possible to repeat this trick.

Nick also found some optimisations by removing some accuracy of some of the numbers. Pretty soon, he'd reached a size which he was happy with. Then I spotted one more optimisation. You're not going to like it, I said, by way of introduction, before pointing to the final character of the JavaScript: a line terminator.

Nick deleted it without a moment's pause.

What surprised me about this was that I feel that any of Nick's colleagues could have helped him with this task. Sometimes making suggestions is not even required. Asking what E is can be enough to trigger a thought in the original programmer's mind.

Top comments (0)