RSS Feed for This PostCurrent Article

Why Code Review is important?

Beside design review, code review is a must-do during software/system development.

There are many software projects that I have implemented. Some projects are continuation from legacy applications that have been developed years ago. The developers are no longer in the companies and most of the time we have to do a lot of guess works on the source code. At times, the source code could have been refactored much earlier in the development stage. Once goes into production, the cost of fixing the code is high.

As a simple example, have a look at the following code

try {
    ServiceA obj = new ServiceA();
    registerToRegistry("ServiceA", obj, true);
} catch (RemoteException ex) {
    ex.printStackTrace();
} catch (MalformedURLException ex) {
    ex.printStackTrace();
}
System.out.println("ServiceA started successfully");
 
try {
    ServiceB obj = new ServiceB();
    registerToRegistry("ServiceB", obj, true);
} catch (RemoteException ex) {
    ex.printStackTrace();
} catch (MalformedURLException ex) {
    ex.printStackTrace();
}
System.out.println("ServiceB started successfully");
 
.........

The code registered at least 10 RMI services to the RMI registry.

This piece of code is carried forward for a few years. So each time a new functionality is introduced, it has to be manually added and compiled.

It could have been easily refactored so that the start-up is configuration based.

<services>
 
        <service>
            <name>ServiceA</name>
            <class>com.sample.ServiceA</class>
            <server>localhost</server>
            <port>1025</port>
            <binding-name>ServiceA</binding-name>            
        </service>
 
       <service>
            <name>ServiceB</name>
            <class>com.sample.ServiceB</class>
            <server>localhost</server>
            <port>1025</port>
            <binding-name>ServiceB</binding-name>            
        </service>
for (RMIConfig rmiConfig : services) {
   try {
       if (log.isDebugEnabled()) {
           log.debug("Starting " + rmiConfig.getName());
       }
       if (
               StringUtils.isBlank(rmiConfig.getBindingName()) &&
                       StringUtils.isBlank(rmiConfig.getServer())) {
           Object obj = ObjectFactory.create(rmiConfig.getClassName());
       } else {
           Object obj = RMIUtils.registerService(rmiConfig);
       }
   } catch (RMIException e) {
       if (log.isErrorEnabled()) {
           log.error("Error starting service: " + e.getMessage());
       }
   } catch (Exception e) {
       if (log.isErrorEnabled()) {
           log.error("Error starting service: " + e.getMessage());
       }
   }
}

Nowadays a lot of software projects are being outsourced or developed off-shore due to cheaper cost. My view may not be right, but most of the time I perceived that when we have this kind of off-shore or out-source projects, some developers do not see the importance of writing maintainable code. At the end the project is delivered on time but on a long term the persons who need to support or enhance the system suffer.

By doing code inspection, the impact of this can be minimized. Besides, by inspecting the code you could find simple bugs much early in the development phase and also verify if the programming logic matches the design requirements.

There are many open source tools that I have described previously that can be used to aid code review or inspection in software development. So make full use of the tools!


Trackback URL


Sorry, comments for this entry are closed at this time.