Code Quality : Myth or RealityWelcome to CodeSpread!
What is Quality?
Generic definition of Quality “The standard of something as measured against other things of a similar kind; the degree of excellence of something” . So what i can add here is that quality can be measured only by comparing an item with someone of the same origin. It’s an iterative process which keeps on evolving so as to achieve a better of its own kind. Phew! Complicated? Really, There can not be a definite definition to quality and we can only relate it to the consumer’s satisfaction like if a consumer is satisfied, product was of good quality and if a customer is unhappy, product was of low quality. User satisfaction is the only measurement tool to assess quality.
What is Code Quality?
What we have defined above applies to our code. Till the time, client is not satisfied, our work is not over. But We have to put down a limit to this iterative process and find out the minimum guidelines required to achieve code quality. It is not possible to create the best code but an attempt can be made to achieve a better code by following few guidelines. Code Quality is a myth, if only the best code is available and a reality, if an option of better code is available.
What is the current scenario?
I wonder why people are so ignorant of code quality especially in the services sector where the stress is given to project completion and time lines. It works for a shorter period but when the client wants to do some modification or up gradation to their software and task is given to new developers or even existing developers, they are not able to perform the desired modifications.
Where is the Gap?
Gap is the poor quality of the code. Once we start our project, we seldom think of the quality, as our main focus is on to complete the project and clear all the necessary scans and reports. One more factor is foresight like we fail to visualize all the problems which might crop up in the software development life cycle, they might be complex, too time consuming, requires more effort or which are not easy to fix. We take the easy route to solve these problems and compromise the code quality.
We are going to take help from MSDN and other resources to make code quality a reality.
Steps to achieve Code Quality.
At each stage of Software Development Life Cycle, there is a possibility of improving code quality
- Bore your clients : This is the first suggestion, try and gather all the requirements from clients. All the documents possible, all assets like images , all copdecks , all mapping documents, all SEO related documents. Basically, This is an exercise where you can save your code from having any last-minute introductions.
- When you receive all the requirements, Prepare all your queries and get all the feedback. This is a phase where an understanding between the coders and the clients develop about the final product and both should be aligned. This phase is crucial for decisions related to design and development.
- Say “No” to all the requirements which are not feasible. In the real world, there is no way to achieve all the desires of client so when you think of something of this sort, go ahead and say ‘No’.
- Don’t compromise with the schedule. Put your design and understanding and get a schedule which is feasible and not a shadow plan which will disappear once your project will see the daylight.
Design and Development
- Prepare all the design documents to maintain integrity:
- Use Case shows the actors, cases , the interaction between them and the dependencies .
- Class Diagrams shows the classes, attributes, operations, and the relationships between them.
- Sequence Diagrams shows the interaction between the given classes/objects.
- Insist on quality check-in: Each check-in should go through a review to avoid low quality code during code check-in.
- Conduct code reviews: The purpose of review is to carefully understand and analyze design and code. Code reviews give you an opportunity to explain and better understand your own code.
- Write unit tests: Code written should pass all the unit test cases. To ensure quality,write tests that validate data and algorithms and verify that prior mistakes do not recur.
- Use code analysis tools: The simplest way to catch bugs early is by increasing the warning level in your compiler and using code analysis tools. The critical points are to never ignore a warning and fix the code.
- Avoid Features without a specification: Do not write code without a specification. write a specification and have it reviewed.
- Use a consistent coding style: When a consistent style of coding is followed, code will have the desired readability, consistency, maintainability, and overall quality.
- Refactor existing code into smaller functions: Refactoring can bring new life to old code. separate large functions into collections of smaller functions without changing functionality at all.
- Review existing code: Bugs often congregate in specific modules. When your new code is clean but there are certain modules of your old code that harbor bugs, review just those modules.
- Step through all code paths in a debugger: One of the best ways to verify code is to step through it in a debugger. At each line, verify that what you expect to occur is actually happening. To step through all code paths in a debugger is like a line-by-line unit test. The procedure is tedious, but it effectively verifies expected behavior.
- Ensure all the testing is done.
- System testing: System testing of software or hardware is testing conducted on a complete, integrated system to evaluate the system’s compliance with its specified requirements. System testing tests not only the design, but also the behavior and even the believed expectations of the customer.
- Integration Testing: Integration testing is any type of software testing that seeks to verify the interfaces between components against a software design.
- User Acceptance Testing: User Acceptance Testing (UAT) is a process to obtain confirmation that a system meets mutually agreed-upon requirements. A Subject Matter Expert (SME), preferably the owner or client of the object under test, provides such confirmation after trial or review.
- As code quality is an iterative process, do periodic checks of your code to prevent any errors and improvisations.
These are the guidelines required to be followed to ensure good quality of your code. If you prefer automation, go for tools like FxCop etc. to achieve the same. Now, Visual Studio can also be configured to achieve code quality.if you have Visual Studio 2012, read this article :http://msdn.microsoft.com/en-us/library/dd465186.aspx.
I hope this article helped you, Please share your comments or write me at email@example.com.