Making your code readable is far better than reducing the lines of code. The latter may reduce memory usage but the former ensures that code is easily understandable. In such a codebase, reading a few lines is enough to understand what is happening and how it’s happening.

Also, readable code is not for the creators alone. Readable code is also for every contributor (external or internal, now and in the future) of a codebase.

Readable code makes debugging easier and improves speed in learning and development. Improving  understandability in code is a great step to being a great programmer.

In this article, we’ll look at 5 tips for making your NodeJS code easier to read and understand.

1. Naming

You must have seen this coming.  Naming is the second hardest thing in computer science. Nonetheless, it is our duty as developers to ensure we name our functions and variables properly. This could make the names longer, but the end goal is making them understandable.

Two tips to ensure good naming for functions are:

  • the action involved (addTwoNumbersgetAverage)

  • the returned value (isUserLoggedIndoesCookieExist)

In the first tip, you’ll notice that the name relates more to the action (adding numbers, getting average). It can be easy to quickly assume what is going on in the function.

In the second tip, you’ll notice how the name relates to the returned value (true or false) and it may not be easy to depict what goes on in the function.

However, these two tips make the functions readable. For cases where naming becomes difficult to concisely describe the purpose of a function, comments can be used.

#coding #writing-code #nodejs #javascript

Top 5 Tips for Making Your NodeJS code Easier to Read
4.45 GEEK