Member-only story
12 Conventions for Writing Clean Code
Your peers will thank you later
Coding conventions are the style guidelines for programming. Programming best practices and principles are included in this. Here we will discuss some coding conventions.
Benefits of Following Conventions
- Clean code
- Quality of code
- Readability of code
- Makes code maintenance easier
“Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control.” — Robert C. Martin
1. Magic Numbers
A magic number means we are assigning a number with no clear meaning. Sometimes we use a value for a specific purpose, and we don't assign the value in a meaningful variable. The problem is that when someone works with your code, then the person doesn't know the meaning of that direct value.
2. Deep Nesting
Sometimes we use nested loops that are difficult to understand. The way to handle that is to extract all loops into separate functions instead.
Suppose we have an array of another array that contains another array, and we want the value of the last array. We can write a nested loop that will work for our requirements. But this is not the proper way. Here I have written a function that can do the same, but this one is much cleaner, easier, less repetitive, easier to read, and reusable.
3. Comments
This one is a kind of personal attack on someone. Comments help people to understand later, and…