Search This Blog

PROGRAMMING METHODOLOGY


Introduction
Every programming language has a particular format following some rules. Numerous programming languages have been developed.  A lot of research has been done on programming paradigm and over a period, many new concepts have emerged in programming approach like Procedural programming. Structured programming, modular approach, object oriented approach etc.




Modular Programming
A lot of research on Programming methodologies have resulted in invention of effective and efficient approach in programming. Modular programming is one such approach which emphasizes more on dividing the functionality of program into different small independent units called modules.
Modular programming is dividing a larger / complex program into smaller/ simpler independent sub programs functioning in coordination to get the final output.
Modular programming helps in making the program easier to understand. Advantages of modular programming :-
1.      It makes the program easier to understand
2.      Code reusability
3.      Simple design
4.      Easy Debugging: Errors can be easily identified.
5.      It defines logical division of the program code and helps in easy maintenance.
Above mentioned characteristics of modular programming makes it compatible with Object oriented programming.




Program
A program consists of a set of instructions that perform a specific task. These instructions use various constructs and expressions to perform the calculations. A good program consists of clear and defined set of instructions and uses indents, comments. Some characteristics of a good program are:-
1.       Clarity and Simplicity of expression :
The instructions and aim of a program should be clear and simple. Simple expressions are easy to understand andhelp in easy debugging as well as maintenance.
Complex instructions/ logic leads to confusions and complexity in error finding.
An expression consists of a set of values on which the operators function.
i.                    Purpose of output/ aim of the expression should be clear to the user.
ii.                  Avoid using complex / tricky expression because the user may lose his focus from the main analysis of the program.
iii.                Standard library functions should be used as it saves time and reduces complexity while developing a program.Use of standard library functions.
 For example :
a.      a simple expression to find sum of three numbers x,y,z is
                                            x+y+z
                        b.         An expression to find average of marks in five subjects:
                        Average = (m1+m2+m3+m4+m5)/5
2.       Use of proper names for identifiers : identifiers are the words which are used to name a variable, value, function or a data type. The names used for identifiers must be logically related to its purpose. Suppose, we have to store a value of sum of two numbers then it is advised to give the name of the identifier as sum. Later we will study some naming conventions and valid identifiers.
3.       Modularity
It defines boundaries of logic and hence divides the program into smaller units. These units are weakly dependent on each other.
4.       Indentation
Indentation is the blank spaces left in the beginning of the sentence. It helps in reducing the complexity of the program. Error finding becomes simple. Indentation helps in structuring the flow of program structure. Writing a program with proper indentation is called pretty typing.
5.       Comments
A comment is the textual remark written help within the program. It is also used for documentation of the program. Comments help in understanding the meaning and purpose of code at various steps/levels .
Comments given in the code are not executed and do not have any impact in execution of the program.  WE can also say that comments are non-executable statements in the program.
6.       Documentation
It is and important part of programming as it explains all the procedures and their functions to the user and programmer in detail. It helps in easy maintenance and working with the computers. A program should have a self-documenting code i.e. the names of variables used should be logical and self-explanatory. Every program should be documented properly.
Documentation helps the end user to fully utilize the functionality of any application.
7.       Program maintenance
Maintenance is the most important phase in the development of a program. Modification of the program to remove the errors is done .
8.       Flexibility
Flexibility of a program means that we should be able to make some minor changes without rewriting the whole program.
9.       User Friendly
A program is considered to be user friendly when a user is able to work with the program with ease and comfort. The instructions should be very clear. The interface of the program should bear clear messages for the user. For example,consider a program asking the user to enter a value. The user should be aware of the type of the value that is required as output. If clear instructions are not given user may not be able to judge what value is he supposed to enter? If we consider a case in which user is asked to enter his first name then it is very clear from the question that user has to enter his first name.
10.   Portability
Portability of a program refers to ability of an application to run properly on various platforms. Platform of a computer includes its hardware configuration and operating system. A program is portable if it works perfectly (with minimum changes) on various computer irrespective of their variation in platform. Most of the apps and software these days are platform independent. Portability of a program enhances its usage and popularity.
11.    Robustness :
Robustness of a program means that in case of any error the program should not halt and it must give a suitable / understandable response to the user. A program is considered to be very robust if it does not halt abruptly due to some error.



Steps to design a program for a problem
Wedesign and develop a program it must be done through a set of sequential steps to attain best results. Programminga software also involves following steps:
1.      Problem Understanding: It is themost important step as the all the later steps depends on understanding the problem. Theproblem for which the program is to be coded must  be properly understood and defined.
2.      Problem Solution: Based on the understanding and analysis of the problem a possible working solution is designed. A wrong analysis can lead to hazardous results.
3.      Program Design: It involves designing of raw/ skeletal structure of the program with all inputs and outputs. It involves designingofthe logic for solving the problem. Algorithm and flowchart are useful tools for designing the program before any code is written.
4.      Identifying minimum number of inputs: all the required inputs are identified for solving the problem. The form and order of inputs is recognized in this phase.
5.      Writing optimized Code: it involves writing the code in programming language as per the designed algorithm. Algorithm should be efficient to use all the variables to their optimum. Extra variables and unnecessary steps reduces memory wastage and performance of the program. The algorithm should clearly define the solution with easy and simple steps. Easy and simple steps make it easier to write the efficient and error free code. A program using less memory and least steps to solve a problem are considered to be the most efficient.
6.      Testing and maintenance: It involves testing the program with all possible varying inputs. In case any erroneous results appear the code is modified. This step involves removing of the errors and modifying the program(debugging).
Any unwanted functioning or output shown by a programis called an error. Error can be of three types :
a.      Syntax error : this type of error occurs if there is any mistake / error in the programming language grammar while writing the program code. Every programming language has its own set of rules and specifications.In case the programmer has made any syntax mistakes then they are detected while compiling the program.
For example:following code will give an error on compiling the program.
int A;                            //statement 1
  A=10              //statement 2
            Statement 1 will show an error on compilation as every statement must be terminated with a ; (semicolon) symbol in C++.
b.      Logical error: This error is due to error in the logic development of the program. The program might be correct syntactically and giving the result also but the result is wrong.  These are the most difficult ones to find Such type of an error is called logical error.

For example, if the user has written following code for adding three numbers :
inta=10,b=20,c=30,sum;
sum= a*b+c;
cout<<” sum of the numbers is “<<sum;
Output of the above code will be 230 instead of 60.

Syntacticallythe above statement is correct but will yield wrong results because of the wrong logic.

c.       Runtime error:An error which occurs during the execution of the program. Such type of errors might result in abnormal termination of the program execution without any appropriate message. One of the most common errors is “division by zero”.  For example: if the user wants to find the result of division of two numbers then the denominator value should not be zero because in computer it will lead to termination of the normal execution of the program and will flash for runtime error. Programmer must be careful while writing the code to handle these errors. 
d.      Semantic error : An error which is due to incorrect meaning of code. It occurs during execution like use of an uninitialized variable.

7.      Breaking down problem: The problem is broken down into independent modules for distribution and clarity of problem. There are two methods :
a.      Top down approach: The main problem is broken into modules and these modules are further broken into sub modules to get the solution. It begins with high level design and ends with low level design. The procedure of a procedural programming is Top down approach.
b.      Bottom up approach:It begins with low level design and ends with high level design. C++ and Java object oriented programming languages that follow bottomup approach.
8.      Identification of arithmetic and logical operations: It involves devising appropriate logic for the problem and all the calculations required to process the inputs to get the desired outputs.
9.      Implementation and documentation :Documentation of the program is done . Documentation involves description of all the procedures and logic of the program. For user the documentation manual consists of all the specifications for efficiently using the program.  Finally the program is implemented in the environment for which it is designed and developed.

No comments:

Post a Comment