Programming is all about solving a particular problem through computerized codes. Whether it be a problem of inventory management at any shopping complex, marks evaluation of OMR sheets, running of a remote car, or even running of a missile. Thus the scope of programming ranges from very simpleton tasks to extremely complicated ones. But behind all the codes, one parameter is common, that is, to handle and solve the problem efficiently. As one can’t learn to fly an aeroplane simply by watching it flying, one has to actually learn it. Similarly to become a proficient coder, one has to actually do the codes. And, the task of coding is extremely easy once one learns how to apply the logic for problem solving.
Computer Programming comprises of the fundamental entities which are writing, testing, troubleshooting, debugging, and maintaining of a computer program.
- Writing involves writing down on a paper what is the desired output of the code. This can easily be done by drawing a flowchart which depicts all the steps involved from starting to end. Then writing also involves writing the first copy of the course actually onto the corresponding software. Then the written code has to be tested.
- Once tested, if there are some errors, then those errors has to be removed. This process is called troubleshooting.
- To determine the exact location of the error in the code is executed through a process called debugging.
- After successful completion of all these steps, the program is being executed to obtain the desired result. This is called running the program.
A program is called an efficient program only if it gives correct output corresponding to every input, including the wrong input. The systematic approach to write such an efficient article involves two steps:
a) Program Structure and b) Program Representation. While the former is implemented by using bottom-up or top-down approach and is termed as “popular approach” ; the latter is used to make the code more readable and comprehensible.
What is an efficient or good program ?
A good program is one which produces faster and accurate results and should occupy less space in the computer memory. This constraint on the memory space is often termed as memory constraints. The eminent programmers of the world have agreed upon a list of habits which are considered good for programming.
This list contains:
- Clarity and Simplicity of Expression: Operators, Operands and Constants constitute to form an expression. To ensure the clarity and simplicity of an expression, following points should be kept in mind :
- Use library functions to make programs more powerful
Find Output = x4 Output = x*x*x*x We can use output = power (x, 6)
- Follow simplicity to maintain the clarity of expression
X = (A + B) / (A - B) - (U + VY) / (X + Y)
We can simplify it and write as:
X1 = (A + B) / (A - B) X2 = (U + VY) / (X + Y) X = X1 - X2
- Avoid program tricks usage, the meaning of whose is difficult to comprehend by the user.
- Use library functions to make programs more powerful
- Use of proper names for identifiers: User defined names which are used to name things are called Identifiers. A name associated with any function, constant or variable is used to refer to that particular object. Only letters (A-Z, a-z), underscore character ( _ ) and digits (0-9) can make up a valid identifier. However, digits can not be used to start the name of any identifier.
- A meaningful name for a data object (variable) and function should be used.
To find area of a rectangle Use the variable names as length and breadth Area = length * breadth
- Meaningful names of constants should be chosen.
E = 2.71 Use instead euler_constant = 2.71
- Similar names like book, bookkeeper or library, librarian should be avoided.
- One letter identifiers like a, b, c should be avoided. Instead use more relevant names like age, name, first_name etc
- A meaningful name for a data object (variable) and function should be used.
- Comments: To enhance the readability of a program, comments are used. These are used to embed programmer-readable annotations in the original or source code of a program. These comments are profoundly important for the programmer but are simply overlooked by the compilers and interpreters. Comments should be added in the program in simple English language where they denote why a particular function has been used in the program or to specify the reason to use any particular data object or function in the code. Comments are generally categorized into two categories, viz, “Block Comments” and “Line Comments”. Line comments are single line comments while block comments are usually multi line comments. The symbols to denote block comments and line comments are different in different languages. However, the symbol for block comments can also be used for line comments. In python for example, Block comments are implemented by “”” and “”” while line comments are implemented by #. Lets take an example:
“Write a program using while loop in python to print a sequence of numbers from 1 to 50.
while (n < 50); # While loop
n = n + 1
- Indentation: Indentation is defined as the process of leading white space (tabs and spaces) at the beginning of each statement. It is used to determine the group of a statement. Lets take an example:
# Let Anshul and Vivek denote age of two brothers
If Anshul > Vivek
print ‘ Anshul is elder ‘ # Block 1
print ‘Vivek is elder’ # Block 2
In this example, the ‘if’ block being used is a type of code block. If the ‘if’ condition evaluates to true, the Block 1 is executed, else (otherwise) Block 2 is executed. Though, the individual blocks can have multiple lines, but it’s conspicuous that a proper indentation makes the visibility of a particular block easier and simpler.
Characteristics of Good Programming
What happens, if we bury a seed of mango under the earth. After many years a mango tree will be grown at that place. Well, it’s is a very fundamental thing. The concept of the idea is that ‘input determines the output’. And this concept applies even in programming. To yield/provide correct and desired output, we need to feed/provide the computer with proper and correct instruction set. The characteristics of a good program are as follows :
- Flexibility: It should be possible to accommodate modifications in the program without having the requirement to write the entire code again. The program should be able to serve multiple purposes. For instance, CAD (Computer Aided Design) software can efficiently be used to serve diverse fields like engineering drafting, industrial art, fabric designing, printing circuit layout and designing, architectural drawing etc. Most softwares are developed for a particular period and updations are required to make the software adaptable for serving new purposes as well.
- User Friendly: User friendly programs are those programs which can easily be understood by a beginner. The interaction between user and program should be easy to understand. The commands in the program like to input data, to print result, etc. must easily be comprehensible by the naive user.
- Portability: The ability of a program to run on different operating systems without having any or minimum changes is termed as the portability of the program or application. With the rise of numerous platforms having different operating systems embedded within them, and with the availability of various hardware and softwares, portability is something which is being taken care of by every application developer these days.Without portability, a program highly usable for one one platform becomes obsolete for another. Program developed in high level languages are generally more portable than programs developed in assembly level languages.
- Reliability: Reliability of a program refers to its ability to perform its intended function accurately along with certain modifications. The ability of a program to handle exceptions of wrong input or no input is one of the fundamental behaviors which define reliability. Although, the program is not expected to produce correct result in these exceptions but it should be able enough to provide an error message. A program equipped with such a characteristic is called a reliable program.
- Self-Documenting Code: A self-documenting code is the source code, in which suitable names for the identifiers are being used. Proper names for the identifiers makes it easier for the user to understand the functionality of a particular variable or consonant (identifier). Hence, it is advisable that every good program must have a self-documenting code.
Modular Approach to Programming
Often there are very long codes in the practical world. These codes are written to perform various functions or tasks. Now, an efficient program or code is one where the lengthy code is being divided into different sections/modules. This process of dividing a long code into different sub codes is called modular approach to programming. These different modules are often termed as functions in a program.
Take for an Example:
Let the code below represents a program to evaluate percentage of a student in 10th class exam.
Input marks of first subject Input marks of second subject Input marks of third subject Input marks of fourth subject Input marks of fifth subject Add marks of all subject Multiply the total marks by 100 Divide the above result by 5 Output the result as percentage of the student.
Now, the above program is a brief illustration of how a lengthy program can be even more difficult to operate with. Now, as per the modular approach, the above program looks like:
Input marks Get total marks Evaluate percentage Output result
This is called a modular approach to programming and should be followed with long programs.
Documentation and Program Maintenance
In the modular approach of programming we saw that different modules help to deal with the program in an efficient way. In the pragmatic world, where the codes are longer than usual, different modules of a same program are developed by different departments of the organization. These modules are thus required to be properly documented and maintained so that each department can use them efficiently. This procedure is called documentation and maintenance of a program.
Guidelines for a good document are as follows:
- Documentation should be done from the reader’s perspective.
- It should not be ambiguous.
- Repetition of documents should be avoided.
- While preparing the document, industrial standards should be followed.
- Regular updation of documents should be done.
- Outdated documents should either be removed or updated.
- Merits of Documentation
- Helps to track the complete program in a modular way.
- Easier maintenance
- Enhances quality of the software
- Code becomes comprehensible to developer and others as well.
- Makes user – training easier
- If the first developer leaves the job in between then the new developer can easily get acquainted with the ongoing work.
- Types of Documents
- User manual: It is like a ‘How to use’ guide for the end users.
- Operational Manual: It contains all the operations and their inter dependencies which are being used in the program.
- Design Document: It enlists all the design aspects of the program and contains diagrams like data flow, entity relationships etc.
- Requirement Document: It enlists the requirements to run the software efficiently.
- Technical Document: Components like program codes, algorithms, functional modules etc. are listed in this document.
- List of Known Bugs Document: In this document those bugs or errors are listed which were discovered later and thus couldn’t be removed from the software.
Errors and their types
Errors are unwanted aberration that occur in a program because of illegal operation performed by the developer or user of the program. Errors are also termed as ‘bug’ in programming language. They are not detected until the program is compiled or executed. The common types or errors are as follows:
- Syntax Errors: Syntax errors or compile time errors are errors which occur when the proper writing rules of a particular language are not followed. Each language has a set of instructions which has to be followed while writing a code in that particular language. These errors are called syntax errors. Since these errors are detected by compiler at the time of compilation, thus these are also called compile time errors.
a = int(input('Enter a number: ')) whille a%3 == 0: print('The number is divisible by 3.') else: print ('The number is not divisible by 3.')
Notice that the “while” keyword in above code is not spelled correctly. These type of errors are called Syntax errors.
- Run Time Errors: These are errors which occur while the program is being executed, hence also called execution time errors. These errors result in abrupt completion of the program or the program may also enter an endless loop.
a = int(input('Enter a number: ')) b = 0 whille a%b == 0: print('The first number is a multiple of second number.') else: print ('The first number is not a multiple of second number.')
Notice that the second number is by default set to zero. Now a number divided by zero results in infinity which is not known. Such errors are called runtime errors.
- Logical Errors: These errors as self explanatory by its name, occur due to the implementation of incorrect logic by the developer of the program. These errors are not detected while compiling or executing the program.
x = float(input('Enter a number: ')) y = float(input('Enter a number: ')) z = x + y / 2 print ('The average of the two numbers you have entered is:', z)
Now, as per the desired goal, the above program is expected to give the average of two numbers x and y. But it doesn’t produces the desired result. Because firstly, y is being divided by 2 and the result is then added to x. Thus incorrect logic is there. As per the correct logic, the developer should have written :
z = ( x + y ) / 2
These types of errors are called logical errors or semantic errors.
- CBSE Class 11 C++ | Sample Paper-1
- CBSE Class 11 C++ | Sample Paper -2
- CBSE Class 11 C++ Sample Paper-3
- CBSE Class 11 | Computer Science - C++ Syllabus
- CBSE Class 11 | Problem Solving Methodologies
- CBSE Class 12 | Computer Science - Python Syllabus
- CBSE Class 11 | Computer Science - Python Syllabus
- CBSE 12th class Paper Solved - 2015-16 session
- CBSE Class 11 | Mobile Operating Systems - Symbian, Andriod and iOS
- Software Concepts
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- Difference between Functional Programming and Object Oriented Programming
- Modular Approach in Programming
- 5 Best Programming Languages For Newbies
- Blog | Programming Guidelines
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.