Painless Software Development Part 3

July 3rd, 2010 by Kevin | Posted under development.

Before reading further, please read:
1) Painless Software Development Part 1
2) Painless Software Development Part 2

Development
Once the best design for the system has been chosen based on the requirements, it is time for the ideas to actually take physical form by the process of implementation or development. The implementation phase will also contain some designing such as the level of modularization that we need to achieve when we are implementing a function or a module. Following are some of the techniques to use during the development so that we can achieve a bug free implementation and be well on our way towards painless software development.

1) Compiler Warnings
When we use the compiler for development, many of us have a tendency to ignore the warnings by turning them off or setting them at a level that they can be ignored and we can still get the code compiled. However this is a way to hide many of the logical bugs that may be perfectly valid C idioms.
For example,

if(ch = 't')
{
   //do something
}

The intention in this piece of code is to compare the character variable, ch, with the ‘t’ tab character. Even though this is perfectly legal C code, it is a potential logical bug. In many compilers, a warning will be issued when an assignment statement is used in an if condition in such a way. However if the compiler is set to ignore warnings, then you will not be able to find this bug until possibly later in the development process.

Another example is the warning generated for type conversion. Assuming int has 2 bytes and you have a function,

void calculate(int a)
{
   //calculate an equation with a
}

unsigned int b = 65535;
calculate(b);

The implicit type conversion of the unsigned integer to a signed integer when it is passed into the function will generate a warning but if the compiler ignores such warnings then the result will not be what you expected.

The best way to ensure that such situations are detected and fixed as early as possible is to have the compiler report all warnings as errors so that you cannot have a compiled version of your code unless you have resolved all the warnings. Doing this can save you a lot of time as the compiler automatically detects potential bugs without you having to expend too much effort. Since they help detect potential bugs early in the development process, compiler warnings are a great help in the path towards painless software development.

2) Source Code Checker
A source code checker helps in detecting potential bugs in the system by checking for suspicious use of the programming language. Such a source code checker tool would have detected both of the sample compiler warnings shown in the earlier section. An example of a good source code checker is lint. Lint can help you detect some of the below mentioned problems:

  • Unused #include directives, variables, and procedures
  • Memory usage after its deallocation
  • Unused assignments
  • Usage of a variable value before its initialization
  • Deallocation of nonallocated memory
  • Unreached code
  • Implicit casts of actual arguments.
 

Related Posts:

Tags:

Do you have any comments on Painless Software Development Part 3 ?

Spam protection by WP Captcha-Free