Good programming practices in Software Engineering

There are some good coding practices to follow as a part of a programmer’s career and skill set. In professional life, when you have to work in a team on a project. The project undergoes many phases and in each phase the team members analyze the code for testing or maintenance purposes.

In this case if the code of any team member is not up to the standards eventually it will be very difficult to understand and maintain it. So every programmer must follow these following rules:

  1. Camel Casing: First characters of all words, except the first word are Upper Case and
    other characters are lower case. Use Camel casing for methods and variable names. For
    example,
void FeetAndInchesToMetersAndCent()
{
    //Keep all first letters capital for Functions

    int sumOfQuizzes;      //keep first letter small for first word in variables
    int sumOfAssignments;

}

2. Identifiers for constant should be in uppercase letters. For example,

const double CONVERSION = 2.54;
const int NO_OF_STUDENTS = 20;
const char BLANK = ' ';

3. Use Meaningful, descriptive words to name variables. Do not use abbreviations.

string address
int salary

// not recommended
string addr
int sal
  1. Use TAB for indentation. Do not use SPACES. Define the Tab size as 4. Curly braces (
    {} ) should be in the same level as the code outside the braces.
if (beta >= 10)
{
    int alpha = 10;
    beta = beta + alpha;
    cout << alpha << ' ' << beta << endl;
}
  1. Good and meaningful comments make code more maintainable. However,
  • Do not write irrelevant comments for each line of code, every variable declared and above every function.
  • You can use // or /// for comments. Using /* … */ should be avoided
  • Write comments only when required. Good readable code will require very less comments. Moreover, If all variable and method names are meaningful, it will eventually make the code very readable and will need less comments
  • Do not write unnecessary comments if the code is easily understandable and readable without comment. The disadvantage of having a lot of comments is, if you change the code and forget to change the comment, it will lead to more confusion and difficulty.
  • Short lines of comments will enhance the elegancy of code. But if the code is not readable and there are less comments, that is considered as bad programming practice.
  • If you have to use some complex or weird logic for any reason, document it very well with sufficient comments.


You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.