12 Computer Science Notes Ch3 Programming Methodology
12 Computer Science Notes Ch3 Programming Methodology
Stylistic Guidelines:
Writing good program is a skill. This can be developed by using the following guidelines.
1. Meaningful Names for identifiers: A programmer to give the meaningful names to each
section of the program so that it can help him to identify the variable used for specific
purpose. This helps him to execute the right elements during the complex run of a program.
2. Ensure clarity of expression: Expression carry out the specified action. Thus they must
be clearly understood by the users. There should not be any compromise with the clarity of
expression.
3. Use of comments and indentations: Comments generally are used as the internal
documentation of a program. If comments are used in the program they will guide the
program while debugging and checking. While indentation is the proper way of writing to
avoid the confusion regarding the flow of program. These highlights nesting of groups of
control statements.
4. Insert blank lines and blank spaces: Blank lines should be used to separate long,
logically related blocks of code. Specifically Normally in programming the standard for the
use of spaces is to follow normal rules. This means that: Most basic symbols in C++ (e.g., "=”,
"+”, etc.) should have at least one space before and one space after them.
5. Statements: Each statement should appear in a separate line. The opening brace following
a control statement such as if or while should appear on the line after the if or while, lined
up with the left of the control statement, and the closing brace should appear on its own line,
lined up with the left of the control statement. As an example, see the for loop in Figure 1.
The opening and closing braces for a function should be lined up in the same way. The
statements within a {________} pair are indented relative to the braces.
1. Effective and efficient: The program produces correct results and is faster, taking into
account the memory constraints.
2. User friendly: The program should be user friendly. The user should not be confused
during the program execution. The user should get correct direction and alerts when he is
going through the program.
3. Self documenting code: A good program must have self documenting code. This code will
help the programmer to identify the part of the source code and clarify their meaning in the
program.
4. Reliable: The good program should be able to cope up from any unexpected situations like
wrong data or no data.
5. Portable: The program should be able to run on any platform, this property eases the use
of program in different situations.
Robustness:
Types of Errors
An error, sometimes called a 'bug' , is anything in the code that prevents a program from
Errors that occure during compile time are called compile time errors. There are two types of
compile time errors:Syntax errors and Semantic errors.
Run time errors :Errors that occure during the execution of a program are called run time
errors.
Logical errors: Some times even if you don't find any error during compile time or runtime,
but your program gives you wrong or unexpected output. This is because of the incorrect
logic used by the programmer. Such errors are called logical errors.