• Loading
    • Code Construction In Software Engineering

      Continue From.. Software Analysis And Design

      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
      You will now learn how code is constructed. Design provides the basis for code construction. A unit test helps a developer to consider what needs to be done as requirements are nailed down firmly by tests. There is a rhythm to developing software unit tests. First, you create one test to define some small aspect of the problem at hand. Then, you create the simplest code that will make that test pass. Then, you create a second test. Now, you add to the code you just created to make this new test pass, but do not write any more code until you have created a third test. You continue until there is nothing left to test. The next page holds an activity for you. You have to connect the numbers in a series beginning with number one. For example, click number two to connect number one and number two.


      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.

      CODE LAYOUT AND PRESENTATION ASPECTS

      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.
      Code-level readability is not about using comments only. The main contributor to code-level readability is not comments, but good programming style. Check the first example of code provided. This reflects bad programming style. Check the second example. Even though this code does not use any comment, it is much more readable. It takes us toward the goal of "self-documenting code".
      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.
      You will now learn what defensive programming is. As a programmer, you should be able to envisage areas in your programs that can initiate errors in the behavior of the software application. Hence, appropriate methods should be used to prevent the occurrence of errors.
      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.

      ON-SCREEN ERROR AND HELP MESSAGES:
      Now, you will learn the importance of On-Screen Error and Help Messages. In this example, the customer inserts his debit card in the ATM machine. But the machine does not accept the card and ejects it immediately, without showing any error message. This makes the customer frustrated. The next page provides some good practices that should be followed in case of text-based error and help messages. Design of the On-Screen Error and Help Messages have a strong bearing on user-friendliness. This page puts forward some of the guidelines that could be followed by the developer.


      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



    Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.