Code = Language

Valentin PARSY
Frontend Weekly
Published in
2 min readMay 11, 2018

Before starting : the code in this article is written in Typescript but I think this doesn’t stop any developper from understanding what’s going on.

“Now use what I just said to maintain my code”

I had the perfect example recently : I was pair programming with a junior developper when we came across this function :

Challenge for you at home : try to sum up what this function does in less than a minute (the answer can’t be “it updates the infos” obviously, try to explain what it does step by step).

So before adding our code, we decided to rewrite it a bit . Here what we came up with:

Same exercise, one minute, go !
It took you less than one minute didn’t it ?
I wanted to show all the functions we wrote, but I changed my mind : it’s far away from the point I want to make here (plus it would launch a debate on how to cut functions into smaller, more functionnal ones).
Fun Fact : once we did that, we had no trouble finding where to add our code which was supposed to update infos we got from another service …

Always leave the campground cleaner than you found it.

What impressed me the most (not in a good way), was to see how many times people in the past weeks changed this function without ever cleaning it.
For me this rule, called “The Boy Scout Rule”, which is known to be appliable to coding (“ Always check code in cleaner than when you checked it out”), is one of the most important rule in developpement.
You don’t have to leave it the cleanest it can be, just clean it a bit (it can be anything : renaming something, cut a function, add a comment …), because if it is done everytime the code changes, the code will tend more and more to be the most readable and maintainable.

The code you write should be easily maintanable. When someone reads it for the first time, this someone should be able to understand what’s going on quickly … and this someone includes you (because you might have to update this code in 6 months).
You have to think about code readability when you work … and it’s really easy : once you’re done ask yourself if anyone could understand it ? (don’t ask yourself if you would understand it, of course you would).
Ask someone else for example, this is usually done via code review.

The code should be as easy to read as reading a book … because code is like any language.

--

--

Valentin PARSY
Frontend Weekly

Javascript enthusiast. Developper at @sfeir. Follow me at @ParsyValentin