Readability and Simplicity — The New Coding Religion

Amir Harel
Frontend Weekly
Published in
5 min readDec 19, 2018
Photo by Nicholas Green on Unsplash

For the sake of simplicity and readability, the term ReSi will be used from here to the end of the post as a short for Readability and Simplicity.

Now, let's talk about ReSi. I love ReSi as much as the next developer. I think it is an important factor in the coding standards, whether it is a small project, and even more when you are dealing with a large and complex one. It makes the code easy to maintain both by the origin developer or by anyone who might jump-in along the way to review or fix something.

I think the benefits of ReSi are quite obvious, so no wonder it has become a major force in coding style, where many tools were introduced to guide and even force developers in the “right” way of coding.

The ReSi Movement

Being a freelance developer I had the chance to work with all kinds of developers from different companies and teams in the past years. ReSi was always something that developers were aware of and always tried to develop by it. However, I have the feeling that in the last years there is an overrated movement of ReSi fanatics.

It might be as simple as these annoying developers who might trash your pull request with all these small comments to make your code more ReSi, up to full blown fanatics who will code-shame/mock you and will have huge arguments with everything you do, since they think you are not “really” a developer. No matter where they are on this ReSi scale, it seems like they all worship the ReSi way, and it is hard to talk reason into them.

I mean, at some point ReSi is just something of a taste rather than something that is objectively correct.

Let’s see an example

function buyItem(item, requestedDelivery) {
const price = getPrice();
const wallet = getWallet();
const maxDeliveryTime = getMaxDelivery();
const minTimeDelivery = getMinDelivery();
const userRating = getUserRating();
const itemCount = getItemsCount(item);
if (price <= wallet && itemCount > 0 && requestedDelivery >= minTimeDelivery && requestedDelivry <= maxDeliveryTime && userRating > USER_RATING_FAIR) {
buyItem();
} else {
showError();
}
}

In this case, it is easier to argue that we can extract the logic of the if statement into a function or a variable to make it ReSi:

function buyItem(item, requestedDelivery) {
const price = getPrice();
const wallet = getWallet();
const maxDeliveryTime = getMaxDelivery();
const minTimeDelivery = getMinDelivery();
const userRating = getUserRating();
const itemCount = getItemsCount(item);
// the if logic goes here:
const canBuyItem = price <= wallet && itemCount > 0 && requestedDelivery >= minTimeDelivery && requestedDelivry <= maxDeliveryTime && userRating > USER_RATING_FAIR;
if (canBuyItem) {
buyItem();
} else {
showError();
}
}

I mean, you can still argue if this is actually make the code ReSi or not, but I admit that I would have done this small refactor. However, when you have something like this:

function buyItem(item) {
const price = getPrice();
const wallet = getWallet();
if (price <= wallet) {
buyItem();
} else {
showError();
}
}

I don’t think there is a room for ReSi here. However, I actually got several PR comments, similar to this case, asking me to extract the if logic into a function — a FUNCTION??? just to make it ReSi, that is when I started to realise that something is wrong.

I guess a few, if not more of you, will still justify this change request. Stop for a second and really think if this change will actually make things ReSi, or this is just an instinct to try make everything ReSi without realising that this is too much.

Sometimes I just feel it is more of a competition of who is the bigger ReSi fanatic rather then giving constructive and helpful pull requests comments.

Prioritisation Test

I decided to test how important ReSi is for developers and gave 4 coding objectives and ask them to prioritise them by how they think they are important in the development team they are working at right now. Here they are:

  • Functionality — the code achieve the functionality that was required from it
  • ReSi — the code is readable and simple to understand.
  • Robust — the code is error or bug free (as much as possible)
  • Performance & Scalability — the code execute in a good performance both in terms of user experience and scalability.

To me it is really easy to order this list:

  1. Functionality
  2. Robustness
  3. Performance & Scalability
  4. ReSi

Again, before you all jump on me, let me clarify: ReSi should be kept at all time, and most of the time ReSi code is a good indicator for robustness and performance, but, and there is a big but here, what if you had a situation where you had to choose one instead of the other. What if you can not achieve all of these, and you have to compromise, what will you leave for next iteration of the development?

Would you really prefer ReSi over performance? over Robustness, or over functionality? with all of these choice you are affecting the product and the customer, while in ReSi you are only affecting your team. Since I am coming from a user centric point of view (where the user is the king), I would have to set ReSi as the lowest priority in this case.

Wouldn’t you?

Now back the test I did. You would expect that this question that I ask is fairly easy to complete, but not for the ReSi fanatics. Some of them even refused to complete the order since they think that the whole thinking process of this task is wrong and they should not answer it, since ReSi code means all the 3 options together, and it cannot be separated. No matter how much I tried to explain that such situation, where you have to make a decision between these options might occur, they didn’t want to hear anything about it. I have to admit that at some points I felt I am actually talking about religion rather on coding standards.

To be honest, some did complete the ordering and put ReSi in a higher position than I did, but at least in this case I could have a reasonable argument if this is good or not.

To Sum Up

  1. ReSi is very important
  2. But not the most important — so relax already with this ReSi nonsense.

What do you think, am I the only one who think that this is getting out of hand and developers need to keep their priorities in order, or you are with me on this one?

Feel free to share you priority in the comments below, just make sure it is readable and simple ;)

--

--

Amir Harel
Frontend Weekly

Entrepreneur and problem solver, Engineer @ Facebook, tennis enthusiast and Co-founder of 2 amazing kids