The  program development process includes three important stages,  namely, program design, program coding & program testing.  All three stages contribute to the production of  high quality programs. Here we shall discus about program coding .

      PROGRAM  CODING :

          Developed algorithm must be translated into a set of instructions that a computer can understand. The major emphasis in coding should be simply and clarity. A program written by one may have to be read by others later. Therefore, it should be simplicity and readable & simple to understand. Complex logic and tricky coding should be avoided. The elements of  style included internal documentation, construction of statements, generality of program, and input/output formats .

 Internal Documentation:

          Documentation refer to the details that describe a program. Some  details may be built-in as an internal part of the program. These are known as internal documentation.

 The important aspects of  internal documentation are, selection of meaningful variable names and the use of comments. Selection of meaningful names is crucial for understanding the program.  For example

                   area = breadth*length

Is more meaningful than – a = b*l;

 

Names that are likely to be confused must be avoided. The   use of meaningful names also aids in understanding and maintenance of programs.

    Descriptive comments should be embedded within the body of source code to describe processing steps.

Statement  Construction:

          Although the flow of  logic is decided during design, the construction Uof individual statements  is done  at the  coding stage. Each statement should be simple & direct. While multiple statements per line allowed, try to use only one statements per line with necessary   indentation. Consider  the following code:

                             If(quantity>0)  { code  =  0; quantity

                             = rate; } else { code = 1; sales = 0 }

Although it is perfectly valid, it could be reorganized as follows:

                             If(quantity>0)

                             {

                                      Code = 0;

                                      Quantity = rate;

                             }

                                    Else

                             {

                                      Code = 1;

                                      Sales = 0;

                             }

The general guidelines for construction of statements are:

1.     Use one statements per line.

2.     Use proper indentation when selection and looping structures are implemented

3.     Avoid heavy nesting of loops,  preferably  not more than three levels.

4.     Use simple conditional tests; if necessary break complicated conditions into simple conditions.

5.     Use parameters to clarify logical and arithmetic expressions.

6.     Use spaces, wherever possible, to improve readability.

Input/Output Formats:

 Input/output formats should be simple and acceptable to user. A number of guidelines should be considered during coding. Keep formats simple.

·        Use ena-of-file indicators, rather than  user requiring  to specify the number of items.

·        Label all interactive input requests.

·        Label all output reports.

·        Use output messages when the output contains some peculiar results.

Generality of Programs:

          Care should be taken to minimize the dependence of a program on a particular set of data, or on a particular value of a parameter. Example:

                                      For(sum = 0, i =1; i  <= 10; i++)

                                                Sum = sum + i;

This loops adds numbers 1, 2, ….. 10. This can be made for general as follows:

                             sum = 0;

                             for(i = m; i <= n; i = i + step);

                                   sum = sum + i;

The initial value m, the final value n, and increment size step can be specified  interactively durin program execution. When m =2, n =100, and step = 2, then loop adds all even numbers upto, and including 100.  


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet