Your builder has taken your house requirements and has given you the building plan and the prototype of your house. So in your mind, you have the picture of your dream house ready. What do you think is the activity that the builder has to engage in now? Yes. You guessed it right. The builder will need to construct the house now.
At the end of this session, you will be able to:
- Ø Explain what code construction is and in which part of the software development lifecycle code is constructed
- Ø Illustrate the process of code construction
- Ø Describe good programming practices
Now, you know that any unstructured piece of work is difficult to understand and comprehend and that code is no exception. You should remember that even though completed code is an important deliverable that is given to the customer, software engineering is not just coding. Coding (shifting of focus from “what to build” to “how to build” a solution) is a stage within the software development life cycle. The subsequent page explains the coding process in detail. Design documents and unit test cases that are updated with test cases are important inputs for the coding stage. Code construction using language-specific coding standards, peer review of code, and updating code based on review comments are major tasks in this phase. Peer-reviewed code is the output of the coding stage.
This will delves into details of the tasks and activities of the coding stage. It must be noted here that peer review of code is a very important task in the code construction stage.
Before we move forward, let us take a look at the benefits of peer review.
Here you will see what happens if you do not use proper coding standards.
A coding standards document tells developers how they must write their code. Instead of each developer coding in their own preferred style, they will write all code to the standards outlined in the document. This makes sure that a large project is coded in a consistent style, that is, parts are not written differently by different programmers. Not only does this solution make the code easier to understand, it also ensures that any developer who looks at the code will know what to expect throughout the entire application.
This section outlines concepts that are generic in nature and applicable to most software tools and platforms. Platform-specific conventions and guidelines are covered under the relevant company standard. The relevant language-specific standard must be referred to when constructing code in a specific language.
It is necessary to have a good coding layout structure. Good coding structure improves the readability and maintainability of code. A good layout brings out the logical program structure through appropriate use of blank lines, spaces, and indentation. Let us take the example of an essay written by two young students of class five. Student A has used a clean paper with the necessary punctuation marks, spaces, paragraph settings, used uniform fonts, and cases. This is much easier to read than the one written by Student B, which has not been written neatly and clearly. These were the basic tenets of sentence construction that we had learned when we were in school. This is true even when you write your first program.
This page deals with the good practices on code layout and programming. Code layout deals with the structure of the code and the way it is laid out. It affects readability and ease of modification of code. Here are the guidelines to be followed for maintaining presentation aspects of code when fixing a bug.
This page outlines the concepts pertaining to sentence construction that are generic in nature and applicable to most software tools and platforms. Platform-specific conventions and guidelines are covered under the relevant company standard.
When commenting a source code, always use comments judiciously so that we can ensure our code is readable and clear.
Use of headers in a program will not add to its functionality. It is of immense help during maintenance of a program.
Naming conventions for a language should be as per the recommended convention documented in the coding checklist. The benefits of adhering to naming conventions is that somebody going through the program can get an idea about the purpose of various entities from their names, thus enhancing program readability. Conventions bring about uniformity in the way program entities like variables, symbolic constants, procedures, and functions are named. Teams can develop their specific naming conventions for identification of programs.
In this page, you will learn about the declarations standards in a piece of code:
- A program consists of two basic entities, data and instructions. Data elements or structures should be declared and initialized before (executable) instructions.
- All header files and libraries used in the program (whether standard or user defined) should be declared.
- All global variables need to be declared and the number of global declarations used should be minimized so as to reduce coupling between modules.
- All unique or complex variables or data structures should be described through appropriate comments, clarifying the reason for such complexity.
- Functions and their parameters should be declared taking care to ensure that no type mismatches occur during runtime between the calling and called module or function or procedure.
- When using arrays, remember it is cumbersome to handle arrays having more than three dimensions. Such arrays should be avoided.
Continuing with defensive programming ensures that your program is secure and prevents unauthorized access.
Expectations change and hence requirements change, and so it is but natural that programs have to be modified in order to suit the new specifications. This means that the program should be flexible enough to be modified with little or no effort. This page identifies some practices that help in creating modifiable or flexible programs.
Before we conclude, remember the following points whenever you are constructing any code.
In this session, you have learned that:
- Coding is a stage within the software development lifecycle.
- The inputs for the code construction include design document and the unit test cases document.
- The process of code construction involves using design document and coding standards to create code, aligning code to the unit test cases, and peer reviewing code before delivery.
- It is a good programming practice to follow some platform-specific conventions and guidelines that have been documented. This will help the developer to write legible codes.
Next Article:- Testing In Software Engineering