DEV Community

Cover image for Paired down programming
Ross Angus
Ross Angus

Posted on • Edited on

3 2

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.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →