CODING IN SOFTWARE ENGINEERING

Gayathri. B

Coding in Software Engineering

Coding is the process of converting the design of a system into a computer-readable format. During this phase of software development, design specifications are translated into source code. Proper coding, along with internal documentation, ensures that the code can be verified against its specifications with ease.

This activity is typically carried out by programmers (or coders), who are often different from the system designers. The main objective is not merely to minimize the effort or cost of coding itself, but to reduce expenses in later stages such as testing and maintenance. Well-written code significantly lowers long-term costs and improves software quality.

Goals of Coding:

1.Translate design into code – Convert system designs into executable programs that perform the required operations.
2.Reduce future costs – Efficient coding lowers the cost of testing, debugging, and maintenance.
3.Improve readability – Code should be easy to read, understand, and maintain, making collaboration and long-term support easier.
To implement designs effectively, high-level programming languages are preferred. Such languages must possess certain characteristics to ensure efficiency and maintainability.

Characteristics of a Good Programming Language:

A programming language suitable for software development should provide:
  • Readability – Programs should resemble natural descriptions of operations, allowing code to be self-explanatory.
  • Portability – High-level languages should support the development of software that runs across multiple platforms.
  • Generality – The ability to write a wide range of applications without needing expertise in multiple languages.
  • Brevity – Allow algorithms to be implemented with minimal code compared to low-level languages.
  • Error Checking – Provide strong compile-time and run-time error detection to reduce bugs.
  • Cost-effectiveness – Keep overall development and maintenance costs manageable.
  • Quick Translation – Support fast compilation or interpretation for efficient development.
  • Efficiency – Generate optimized object code for better performance.
  • Modularity – Support modular development with independently compiled components for better organization and consistency.
  • Wide Availability – Be supported across major operating systems and hardware platforms.

Coding Standards

To maintain consistency and quality, coding standards define rules such as variable naming conventions, code layout, error-handling practices, and documentation guidelines. Following these standards ensures better readability, maintainability, and collaboration in software projects.
Representative Coding Standards
Adhering to coding standards ensures consistency, readability, and maintainability of software. Some commonly recommended practices include:



1. Indentation

  • Consistent indentation is crucial for producing clear and maintainable programs. It should be applied to:
  • Highlight the body of control structures (loops, conditionals, and switch/select statements).
  • Emphasize the body of conditional blocks.
  • Mark the beginning of a new scope.

2. Inline Comments

  • Inline comments should be used frequently to explain the functionality of subroutines and highlight key parts of algorithms.
  • They help future developers (and even the original coder) quickly understand the logic.

3. Limiting the Use of Global Variables

  • Define clear rules for what types of data can be declared as global.
  • Avoid unnecessary use of global variables to reduce coupling and improve modularity.

4. Structured Programming

  • Always use structured or modular programming techniques.
  • Avoid using GOTO statements as they lead to "spaghetti code," which is difficult to read, debug, and maintain.
  • Exceptions can be made only when explicitly defined in specific language standards (e.g., FORTRAN).

5. Naming Conventions

  • Establish clear naming rules for variables and constants. For example:
  • Global variables – Start with a capital letter.
  • Local variables – Use lowercase letters.
  • Constants – Written in all uppercase letters.

6. Error Handling and Return Conventions

  • Define a consistent approach for error handling across the organization.
  • Functions and modules should follow the same convention (e.g., return 0 for success and 1 for failure, or use standardized exception handling mechanisms).

Coding Guidelines

General coding guidelines provide programmers with a set of best practices that make programs easier to read, understand, and maintain. While many of the examples below use C language syntax, these principles can be applied to almost any programming language.

The following are some widely recommended coding guidelines adopted by software development organizations:



1. Line Length

Keep source code lines within 80 characters whenever possible.

Longer lines may not display properly on certain terminals or tools, and some printers may truncate lines beyond 80 columns.

2. Spacing

Use spaces appropriately to improve readability.

Example:

 Bad:

cost=price+(price*sales_tax);
fprintf(stdout ,"The total cost is %5.2f\n",cost);

Better:

cost = price + ( price * sales_tax );
fprintf (stdout, "The total cost is %5.2f\n", cost);

3. Documentation

  • Include sufficient comments to explain the code.
  • A common rule of thumb: one comment line for every three lines of source code.
  • Good documentation ensures that code is easy to maintain and understand by others (and your future self).

4. Function Length

  • Keep functions short and focused.
  • As a guideline, a function should not exceed 10 lines of source code.
  • Long functions are harder to understand, maintain, and test. They are also more prone to bugs.

5. Avoid goto Statements

  • Do not use goto statements, as they create unstructured “spaghetti code.”
  • Instead, use structured programming constructs such as loops, conditionals, and functions.

6. Inline Comments

  • Use inline comments to explain the logic of specific lines or sections of code.
  • This improves readability and helps future developers quickly understand the intent.

7. Error Messages

  • Handle errors consistently and meaningfully.
  • Ensure error messages are clear, descriptive, and helpful for debugging.
  • Good error handling includes not only logic to detect errors but also providing messages that guide the user or developer.

Our website uses cookies to enhance your experience. Learn More
Accept !