Brittle code. Code rigidity. Code fragility.
Such is the potential fate of programming code when it is too complex, too inflexible or too fragile to withstand changes or upgrades, at least not without investing significant time and effort.
In contrast, “clean code” is software code that is simple, easy to read and understand and easy to change, both by the author or someone else. Code, like the design and architecture of a system, should improve with time.
“There’s only one thing that stops
Speaking to an audience at the Steve Schiff Auditorium and other Sandia sites via
Known in the industry as Uncle Bob, Martin is one of the co-authors of The Agile Manifesto, written in 2001 by a group of thought leaders seeking to encourage better ways of developing software. The manifesto is the foundation of the agile movement, which has spread to numerous areas beyond software because of its ability to help organizations cope with continuous change.
Martin has written numerous articles and books, including “Clean Code: A Handbook of Agile Software Craftsmanship,” which focuses on the best practice of cleaning code “on the fly.” The topics of his talks at Sandia ranged from “The Three Laws of
With great power comes great responsibility
In his opening talk, “Demanding Technical Excellence and Professionalism,” Martin made the case that software developers have tremendous responsibility because of how pervasive and critical software is in our daily lives. He recounted several examples where problems with software had catastrophic consequences.
In the recent Volkswagen emissions scandal, the company developed and installed software in millions of so-called “clean diesel” cars that was designed to cheat U.S. emissions tests. The exhaust control equipment had been programmed to shut off once the cars left regulators’ test beds, releasing pollutants into the atmosphere that exceeded legal limits. Some former employees are now in prison, and Volkswagen has agreed to pay back more than $20 billion to states, dealers, regulators and car owners.
In another example, a software glitch in trading firm Knight Capital’s computers caused it to rapidly buy and sell millions of shares in minutes rather than over what was supposed to be a period of days. The company lost about $440 million in less than an hour.
“What I’m trying to impress upon you is this: Little did we know how important software was going to be. We did not realize that software would be everywhere,” said Martin, who has been a programmer since 1970. “We rule the world. Other people think they rule the world but then they hand those rules to us, and we write the rules that run in the machines that govern everything.”
Software exists to control hardware
The purpose of software is so the behavior of machines (hardware) can be easily changed, he said. “If your software makes the behavior hard to change, your software thwarts the very reason that software exists.”
Making software easy to change is dependent on following design and testing principles, Martin said. “When software gets hard to change, it’s because principles have been abandoned,” he said. Code should improve with time, not degrade.
Martin outlined a list of expectations for the programmer audience, including a steady release of features that work at the end of each cycle, honest estimates of time required for projects, consistent turnaround times, inexpensive adaptability and continuous learning.
Importance of clean code to Sandia
In his introductory remarks, director John Zepper said he’s seen Sandia teams get bogged down with “legacy ball-and-chain code.” Since code is rarely written once and forgotten, writing clean code from the outset is vital, especially when team members change. Code that is easy to understand and change makes it easier for a new person to step in.
“When developers write clean code, they’re helping their future selves and co-workers,” John said.
Clean code also reduces the cost of maintenance
At Sandia, some software teams spend half of their time on maintenance, said manager Manoj Bhardwaj. By applying Martin’s principles, one team, using clean code principles over the past few years, has reduced maintenance costs to less than 10 percent, which translates to savings of millions of dollars over many years just for one team.
“As more and more teams apply these principles and deliver sustainable code, the potential savings Labs-wide could be in the tens of millions,” Manoj said.