Coding creates the backbone of most businesses today, whether it is developing an app for our smartphones or other software meant to ensure smooth technological processes. It is a way we can talk to machines using a logic base and make them do what we want them to do. However, one misplaced figure or apostrophe can result in dire consequences.
NASA discovered this the hard way. In the space war between the United States and the former Soviet Union, NASA launched Mariner 1 in 1962. Its mission was to collect scientific data about Venus. Unfortunately, a few minutes after Mariner 1’s launch, it did an unscheduled yaw-lift maneuver and lost contact with its ground-based guidance system. A safety officer was forced to call for its destruction 293 seconds after launch. Richard Morrison, NASA’s launch vehicles director at the time, testified before Congress that it was due to an “error in computer equations” that led to the space disaster. Additional reports blamed the source on a mistaken hyphen in the code. Others blamed it on an “overbar transcription error” or a “misplaced decimal point”. Similar mistakes can happen on any project, but the Mariner 1’s code error cost NASA and the American government millions of dollars.
Every developer realizes the need for clean code, i.e. code that is efficient and easy to read with no duplication. But clean code is not necessarily healthy code. Healthy code is code that is maintainable. You can have clean code that is elegant but it is still unhealthy and will ultimately slow down development.
So how do you create healthy code?
- High coverage of unit tests. The more a program’s source code has been unit-tested, the easier it is to implement changes at a later date. Often developers fail to understand that if they invest more time increasing their unit test coverage originally, it helps not only the QA’s but themselves with any changes needed later on and results in faster implementation.
- Refactoring code. Refactoring is an essential part of the development process when working on code. The point of refactoring is changing or restructuring the code, without changing its external behavior. This, in turn, should make it more readable and understandable. Refactoring means that you’re actively taking note of the cleanliness of the code when you’re developing. You should also ensure you’re not unintentionally making unwanted changes to the product or app you’re designing.
Legacy code to healthy code
Writing healthy code is easier to implement when you’re starting with new code. But what happens when the code you’re starting with is legacy code? Legacy code is “old” code, i.e. source code that was written for an unsupported operating system, app, or technology. Once legacy code is in production, ideally no one should need to change it.
There are occasions however, when new features need to be integrated into the legacy code. It can very quickly turn the legacy code into spaghetti code. That is when Unit testing should be implemented. It shows the logic behind the code and enables the new team to see which part of the code is broken.
It is crucial to remember that technology is dynamic. You never know when your legacy code is going to be in need of an update or when disaster is going to strike. Both of these scenarios can force DevOps to make changes to the software fast.
The financial crisis following Lehman Brother’s collapse in 2008 spurred changes to the law for the financial services industry. Institutions were faced with a provision that affected financial reporting and auditing. The changes to the law required recoding and implementation in an extremely short time frame.
Our team was called to a financial institution in New York. Since the software already had healthy code, implementing the new code was seamless. It was easy to find exactly where the changes needed to be made, resulting in faster refactoring and little downtime for the organization.
Healthy code = Healthy product lifecycle
Software is not like architecture or engineering. Even the smallest bug can ruin the entire project or lifecycle of a product. You need to make sure everything works and healthy code is key. Even big-name companies are not immune, like the “leap year bug” that caused Microsoft Azure to go offline and Google’s Gmail to save the wrong date for chats in 2012. Sony’s Playstation 3 and Microsoft’s Zune were also similarly affected by this bug. Healthy code means that when something unforeseen does come up, the bug can be found quickly without having detrimental effects on business operations or downtime ensuring your overall software is agile, clear and robust.