Monday, May 2, 2011

Why we need Coding Standards?

What Is the Coding Standard?

In a nutshell, it is a set of rules or guidelines used when writing the source code for a computer/software program. It is often claimed that following a particular programming style will help programmers to read and understand source code conforming to the style, and help to maintain it.

Why we need it?

The best applications are coded properly. This sounds like an obvious statement, but by ‘properly’, I mean that the code not only does its job well but also is easy to maintain and debug. There is a lot of talk recently about the ‘maintainable code’ as it makes more sense that while facing any issue you are not spending time in understanding the code as its written in a way that is not easy to digest & understand. It also a great impact on the revenue of the company because if company is spending more time in maintaining the code than they have less resources/time to think about novel ideas & implement them as market niche & need is keep changing rapidly now a days.

With time & experience one’s adopt his own style of coding where he/she feels more comfortable but when the developers put together in a bigger project and if everyone tries to code in their own style than the confusion, conflict and complexity arises. By adopting the coding standards into your project, one can make sure that code is readable, intuitive and without any surprises because everybody who looks into your code they have the mindset of what to expect in the code as they have the company coding standard document. It also helps you as a develop to come back to your code after couple of weeks/months and still remember what each part is doing and what was the rational behind putting the logic in that particular way.

Some of the main points to consider while building the coding standards are: -

1. How you name the classes/object?

2. How you name the variables?

3. How you name the Constants?

4. How big are the functions/modules? Are they properly named with the functionality they perform? Are they properly called from different sources?

5. Is your code overall flexible? How easy is to do the change? Does it require a hell amount of time to do a minimum change (it happens if you hardcode values rather than using constants)

6. Does your code make use of block when necessary to make it more readable (for example when putting an if block which has lots of statements that can be easy understand if braces are properly used)?

7. Is your code properly indented?

8. Does your code have proper comments? Specially for the logic that is more completed and as a developer you think will aid the reader to understand specific complex parts of the code.

9. Do you create a common functionality in a separate entity (class/object etc.), which is easily reusable from different sources as per the need?

10. Is your code maintainable? If you or anyone else comes back to add new functionality or fix any existing issues, how much time they need to understand it and how easily they can make the change.

You need to discuss these as a team so that everybody is aware of what is expected from them while building any functionality.

The adoption of coding standards should not increase costs. Standards should take care of easy decisions for you, leaving you free to concentrate on the real work. Another reason for adopting coding standards is to pre-empt bugs as the cost of fixing a bug rises exponentially over time. Finding and fixing bugs in the development phase and preferably even prior to unit testing can save hours of time and resources later. Another common area for the adoption of a set of standards is on code commenting. Keep in mind that bad or out-of-date comments are worse than useless: they can cause others a great deal of wasted time and frustration. To quote Sun Microsystems: "When you feel compelled to add a comment, consider rewriting the code to make it clearer".

Now there are lot of tools available that can analyze your code for a particular coding standards (Sun/IBM etc) along with other key things hence adoption of coding standard is more common & easily manageable now as companies now expect a manageable code which adheres the company standards.

I have seen & analyzed it personally with my over ten years of software industry experience. I have gone through many different coding styles within different projects where different developers were involved. What I have learned is that it does not matter what coding standards/guidelines your company adopt, is it as suggested one by the software guru’s or a novel idea (only follows by that company), as long as its properly called out, documented and followed, it is easier for the future developers to adopt with it, read it properly, understand it and mainly maintain it within less time & with no or less effort.

Monday, April 25, 2011

What Is Software Phase Containment/Escape?

What Is Phase Containment/Escape?

Phase containment in a nutshell is finding and removing bugs/defects early in the process of SDLC. It is the act of containing faults in one phase of software development before they escape and are found in subsequent phases.

An error is a fault that is introduced in the current phase of software development.

A defect is a fault that was introduced in prior phases of software development and discovered in subsequent phases.

You promote the concept of phase containment by relating this concept to the organization's costs and profitability. In order to do that you will need to identify the faults that escaped phase and were found in later phases. You will also need to determine the average costs of defects that escape and are found in subsequent phases.

As its proven from the collected data that most of the time spend in the software industry over the maintenance phase which is costly as it approximately takes 40 times as many engineering hours to fix them once they are out in the market.

There are many different activities, which we perform to make sure that we have a better control over the quality and these activities are: -

  1. Static Analysis - Analyzing code for specific coding and formatting errors
  2. Code Reviews – To make sure security and Better Accountability.
  3. Unit Testing Leveraging developer inside knowledge to break the code
  4. Code Complete Criteria - Consistent standard handoff to Test team

There are phase containment metrics, which we can use to make sure that either we are on the track or is this process really working for our organization/company or not. These metrics are: -

  1. Adoption Metric – It’s to make sure that whether we are adhering with the phase containment standards or not.
  2. Effectiveness Metric – Its to make sure how we are doing & how well phase containment is working
  3. Trailing Metric – It’s to find out the downstream impact of phase containment.

So we can say that through this process we can make sure to incorporate QA into all the phases of SDLC (Software Development Life Cycle). It is a shield for Defect Prevention. If QA team performs Requirements Review Design Review and Code Review defects would be few when actual application is tested. That means we have prevented many defects by performing reviews at each stage of SDLC. That ends up in a product/software on which team has more confidence, its easy to launch in the market with no issues hence improving customer satisfaction and demand in the industry/market.