Practical Approaches of How To Code

Mayur Wadekar
4 min readMar 9, 2020

--

As many times, small scale companies having some fast deliverable projects lead to rough and unwanted coding practices, that might not understand the next developers who work in those modules.

Sometimes there are situations where even code reviews also have not done well. So in such situations, some practical coding approaches might help many junior developers to leads their code reusable, understandable and modularized on their own. Some of the practical coding standards you can see here.

Note: There are some generic examples are in the article. No specific coding language is explained there. It is not a language-specific thing.

Image source: 1

Whatever you are going to read next is some mistakes that I have done and got found in code reviews. So let’s get started.

The first thing which I have figured out while coding is developers will not give proper comments while coding. Comments are the medium to communicate with other developers if you are not working on a particular module. So do comments like

Write comments while coding

In the above picture simply readable statements might understand developers as to why code was written for. Also, some business logic to understand your function as well.

The second more common thing to be explored while writing code is the complexity of logic. Too complex logic must get explained well via comments like

Write comments for complex logic

So now we simply understand what steps my code is performing. As explained in the picture as some derivative calculation operations will be there.

If immediate return statement occurring in switch case there is no need to write a break statement in code. Instead of words picture says a thousand words. :)

Unreachable break statement

In the above picture, the return statement simply returns your pointer to the same statements after the function call. So break will never get executed and called unreachable code. So write snippet is below

Corrected code and removed unreachable code

In the above picture, removed break statement as it is an unreachable code.

Never check if the same value will return from the function as it gets.

Same value return from the function

As in the above code, there is no need to check whether the flag is true or false as whatever it is should get simply returned.

Right statement usage

In the above picture, part 1 indicates that if that returned value is no use afterward or else the last statement of your function body then it should get directly return.

Part 2 indicates that if the same value will get used through complex operations but the same value will going to return from the function.

Modularize your code. Modularization is nothing but simply divide your business logic into small functions.

I have got a simple definition for modularity while googling

Modular programming is the process of subdividing a computer program into separate sub-programs. … Similar functions are grouped in the same unit of programming code and separate functions are developed as separate units of code so that the code can be reused by other applications.

Modularization of Code

The right choice of data types. If your application does not deal with the long variable then do not use it instead you can use int. Some of the registration forms contain strings for their gender fields we can use integers instead of a string.

So simply memory management is also we can do while coding to take the right variables to be pass on to the code.

The more practice you could do the more versatile you are going to be.

I hope this article will help some developers to avoid those common mistakes and gain some real-time standardization for writing styles to their coding.

--

--

Mayur Wadekar
Mayur Wadekar

Written by Mayur Wadekar

Software Developer, Human Being

No responses yet