Below are some of the key techniques
for writing a good piece of code I have learnt over the years:
The code written should be organized
thereby making it easy to read and understand. Following the standard Naming
conventions and using sufficient
naming helps
in the readability and use of comments to explain the core complex logic to
help the reader understand the program intentions.
Reviewing the unused code sections
and removing the identified unnecessary code blocks thereby, reducing the both
the program size and confusion that may develop to a new developer of the
system.
Modularity is one key to be followed
to achieve at most code standard. Long code blocks inside a function should be
broken into smaller generic modules. By doing so, Code Reusability can be achieved,
and code size can be greatly reduced.
Optimized
code is the key to achieve the desired result without compromising the
performance of the system.
For
Example, Getting the factorial of a number can be done in many ways:
b. Operator - by using the Ternary operator
Before jumping into choosing the algorithm
to follow, all the complexities (i.e., Time complexity, Space complexity) are
analysed and the solution is chosen based on the given requirement.
Code
written should be easy to maintain and changes to the system should not be a
challenge.
Dependency on an individual should be minimized and hence,
documenting all the key workings of the program is a must.
For
Example, for a new API method written documenting the following is a good practice:
a. Purpose of the method
b. Inputs
c.Output
Good code is something that strikes
the right balance between all the qualities mentioned above.