23 February, 2013

Good Coding Practices.

Whenever a programmer has to transform a problem statement into a program which a computer can execute, one should split the activity in the following manner :

1] Analysis Phase : Understand the problem clearly. [In real life this will involve study of problem domain.].

2] Design Phase : Think of right algorithm or steps to be followed to achieve your goal. Draw flow charts if required to understand flow of control of a program. Decide the function prototypes in such a way that one can make use of these functions as 7 when required. [In real life this might involve top to bottom approach which leads to deciding the functions / their responsibilities / thier interface, communication with other intelligent controllers if any, etc.].

3] Formulating Of Testing Strategies : Before you start writing actual code, one should always think how am I going to test it? How can I assure that the program specifications are met?.

4] Writing Of Actual Code : Write the code by using good coding practices as described below.

5] Testing Phase : Test the written code as per your strategies. Confirm User Interface.

6] Backup Activity : Keep proper backup of tested code so that if required one should be in a position to reuse already written functions. Use a properly defined directory structure for storing your data.

Follow the above tips thoroughly. A Programmer needs to follow the above steps if one is building up huge software for any application. Some can be made a
habit even through your assgiments, because this is the first step towards climbing up the mountain.

Please Visit The Following Articles Of This Blog Before Proceeding Further.
These Links Will Be Beneficial For You & Will Guide You For Better Understanding Of The 'C' & 'C++' Language.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Why one should follow good coding practices?


In a software life cycle around 80% of time of completion of cycle, the software is in maintenance / upgrade mode. in that case people involved at various stages are different. One might have refer to actual code even after years. Therefore, anybody should be in a position to make the required changes & finish off the activity. This is possible only if code is well documented. Actually writing a right kind of well-documented software is an art with your technical skills. Enough necessary documentation should be made.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What Are These 'Good Coding Practices'?


1] Use logical names for variables, functions, file.

2] Use uniform notation through out your code. For Ex. Hungarian Notation.

3] Create user defined header file to include commonly required variable declarations, function prototypes.

4] Code should be properly indented.

5] While documenting your code...
  
     A] Write the purpose of your piece of code.

     B] For 'functions' :

          I] What is task assigned to function, What are the arguments passed to it, What does it return.

     C] Write a clear comment if you have added any statements for testing purpose.
  
     D] While writing actual code distribute it in following sections :

           I] Include files, #defined constants, global variable declarations, global function prototypes, main function, local variable declarations, local function prototypes, user inputs, algorithm processing, function calls, user outputs, end of main, function definitions.




No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.