Skip to content

iamvs-2002/TipsToWriteBetterCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 

Repository files navigation

Tips to write better code

Two Word Answer : Practice & Endurance

Now, once you have a good working knowledge of any one programming language, the following tips may become handy:

  • Indentation

    Try to properly indent your code.

    eg.

    if(condition) {

     //statement
    

    }

    Style is important, not to make code look pretty, but because it helps with reading, editing, and understanding.

  • Comments

    Comments help you to explain the code to others. Comments will help you and others understand why you did what you did. It may seem obvious to you when you are writing it, but will others who work on the code understand it? Will you remember what you did after a month or a year?

  • Naming

    Try to use proper names for the variables.

    eg.

    CASE 1: int a=5;
    CASE 2: int numberOfIndividuals=5;

    As seen from above, the second CASE looks more friendly and is easier to understand as compared to first.

  • Functions

    Try not to repeat same piece of code again and again, rather use functions.

  • Clever Code

    If you are using some tricks, try to explain the same using comments in your code. Else prefer an easily readable and understandable approach.

  • Delete

    Always delete the unnecessary code. There is no point in keeping the old code, and comment it out. It will just look messy and unnecessarily long.

The main keywords to always keep in mind are consistency, simplicity, and readability.