Coding or programming is a central activity for software engineers and a large part of their effort is invariably spent on the design and architecture aspects. Having a good methodology in place is fundamental to help engineers visualize and bring to life the systems they are designing. It is also a key requirement to ensure successful project deliveries. This article underlines the importance for programmers to follow a good methodology.
As the tools and technology of the software industry have evolved, industry players have practiced various methodologies and processes that have allowed coding activities to become more streamlined and performant. In simple terms, the best results of coding can be achieved by:
- Following a set of best practices, including a well-defined methodology.
- Using a highly mature framework that best suits the underlying technology in which the coding is undertaken.
- Using a set of tools that help the programmer concentrate on the coding activity.
How the Coding Process Works
The coding process in any project starts with the solutioning step. In many cases, even the proof of concept (POC) code forms the basis for the later development. In this article, we will cover the best practices of coding, applicable to any typical medium scale development project. In brief, by following a best coding practice, you maximize the opportunity to produce a high-quality software product, delivered within the estimated cost and timeline!
These eight vital steps are followed across many IT industries and are considered as fundamental practices.
1. Finalization of a Methodology (Lifecycle)
First and foremost is finalizing the methodology to be used. It can be either Test-Driven Development, Pair Programming, or an Agile methodology like Extreme Programming. The next step would be to brainstorm and agree on what would constitute the degree of readiness for the coding. This needs to be achieved in the early stage of the project and every developer should be aware of this.
2. Finalization and Use of Development Tools
The second step is very important, as it impacts the design and development activities of the project. Each decision of a tool and technique to use will play a vital role in shaping the application. This step involves:
- Identification of the various infrastructures for the project, such as identifying the various servers required and the standardization of the software to be used, including the OS and the patches that need to be applied. This involves the servers to be used for everyday testing, the SIT and UAT, and which IDE (Integrated Development Environment) to be used (Eclipse, JDveloper, and Netbeans etc.).
- Choosing which build tool and code repository to be used.
- Choosing unit testing tools, like HttpUnit or JUnit.
- Choosing the review checklist.
Tailoring the process to be used.
This step is always to be considered on a case-by-case basis since the methodology applied by each project will differ in many ways. Every developer should adhere to the methodology to be followed while developing the application.
- Proper requirement walk-through should be made on the module that's going to be worked with.
- Developers should agree on what amount of reviews would be done (i.e., peer reviews).
- Developers should agree on whether a planned activity for refactoring the code would be added in the plan or there is no scope for it.
- Developers should agree on when the traceability matrix would be updated.
- Developers should agree on whether the application delivered by the developer would be validated by a BA before calling it as complete.
Also, a best coding practice is to statically analyze the code by using different tools.
4. Coding the Application and Development Process
A good programming approach should result in the development of a finely grained application with minimal defects. Any developer, irrespective of programming languages used, should always write the code so that other developers can understand the purpose of the code that is written. And also, the code needs to be robust and easy to maintain in the future.
The following 9 rules are important to follow while writing an object oriented code (according to ObjectCalisthenics):
- Use only one level of indentation per method.
- Don’t use “else” as a keyword! (It is a keyword in Java/C++/C.)
- Wrap all primitives and strings.
- Use only one dot per line.
- Don’t abbreviate.
- Keep all entities small.
- Don’t use any classes with more than two instance variables.
- Use first-class collections.
- Don’t use any getters, setters, or properties.
5. Check-In Check-Out Process
A standard code check in and checkout process should be followed. The following are some of the tools available to make a code repository:
- Subversion (SVN)
- Concurrent Versioning System (CVS)
- Visual Source Safe (VSS)
It has become a regular practice in the IT industry that a single document or a source code is set up so that it can be edited or used by any member of a team, which facilitates collaboration between team members working from different geographical locations. The main purpose of the this code check-in process is to create a centralized repository of the project code in one location, making the source code available to other developers who may need to work on enhancing the same code. This approach helps in maintaining a revision control of the developed code.
6. Automated Build Process and Deployment Process
While developing a large scale application, it is good to have a Continuous Integration environment (automated build and deployment process) where the checked in code can be marked as “zero compilation issues.”
Continuous Integration is a software development practice where team members frequently integrate their work on the application. This process usually results in multiple integrations during one single day. To avoid basic compilation errors, the following tools can be used: Jenkins Build Tool (earlier known as Hudson Build Tool) and Cruise Control.
7. Testing the Application
Testing is an integral process in the development of an application. It involves preparing the test cases before the coding phase of the software development process.
The very basic level of testing an application in the software development process is the Unit Testing. A unit is nothing but the smallest testable portion of an application.
Apart from adopting the basic level of unit testing, it is also a very good practice to perform Automated Functional Testing using tools like Selenium and Geb Spock, and also do a code coverage analysis. It is a structural testing technique which compares the test program behavior and apparent intention of the source code. Basically, it involves finding areas of a program not exercised by a set of test cases and creating additional test cases to increase coverage.
8. Review and Rework
Several reviews need to be carried out in the process. It could be with the basic step of the code review, where the source code will be reviewed for coding conventions, and basic coding practices may be implemented. Finally, comprehensive review comments always need to be provided after reviewing a source code and module.
There are several benefits to adopting best coding practices:
- A high-quality output can be obtained with minimal rework within the planned efforts, cost, and time.
- A scalable application can be built and delivered, allowing for future changes in the application.
- The SIT (System Integration Testing) and UAT (User Acceptance Test) phases can go on as planned since a majority of issues would already be identified in the unit testing phase.
- The delivered code will meet the expectations of the customers.
- As the application quality is of high standard, it should reduce any rework required (read duplication of efforts).
- Improved risk management.
- Elimination of wasteful investment in resource and time spend.
- Finally, it also makes for a good morale within the development team!
What coding practices do you use?