Static Code Analysis in An Agile World: Establishing A Repeatable Process To Achieve Working Software With Each Iteration
Static Code Analysis in An Agile World: Establishing A Repeatable Process To Achieve Working Software With Each Iteration
Static Code Analysis in An Agile World: Establishing A Repeatable Process To Achieve Working Software With Each Iteration
in an Agile world
To keep pace with ever-increasing customer demands on software functionality and time-to-market
expectations, software developers have had to evolve the way they develop code to be both faster and
higher quality. As part of this trend, the Waterfall method of software development began to give way in the
late 1990s to a more lightweight method of software development: Agile.
And as the use of Agile has continued to grow in the last decade, it continues to mature as well. Software
organizations are constantly looking for ways to improve their Agile environments, and minimizing software
bugs is one area of focus. This paper will demonstrate that several of the core principles of Agile cannot be
fully realized without implementing a repeatable process for ensuring code that is as bug-free as possible.
The approach recommended in this paper is the use of automated static code analysis (SCA) technology to
locate and describe areas of weakness in software source code, such as security vulnerabilities, logic errors,
implementation defects, concurrency violations, rare boundary conditions, or any number of other types of
problemcausing code.
After providing a brief overview of Agile and discussing some of the barriers to achieving agility, this paper
discusses how key capabilities of SCA technology can enhance the Agile development process and empower
Agile teams.
Agile contrasts with the still-popular Waterfall development approach, which is front-end loaded with
comprehensive scope and requirements definitions, and which employs clear, consecutive hand-offs from
requirements definition to design to coding and then to quality assurance. In contrast, Agile incorporates a
continuous stream of requirements gathering that flows throughout the development process. Business people
are involved throughout the release cycle, ensuring that the software being developed meets the true needs of
both the end-user and the business. Change to the requirements and to the overall feature set is expected to
occur as outside opportunities or threats arise.
In short, Agile fully embraces change and Agile teams are structured in such a way that they can receive and
act on constant feedback provided by the build process, by other developers, from QA, and from business
stakeholders.
Agile is based upon a number of guiding principles that all Agile teams follow. For the purposes of this
discussion, four principles — or values — are of particular interest:
roguewave.com 2
STATIC CODE ANALYSIS IN AN AGILE WORLD
Delivering a series of market-ready products, each in just weeks, demands that a rigorous quality process be
built into the Agile development cycle. Deliverables in each iteration must be fully developed — meaning tested,
defect-free, and complete with documentation.
Iterative flexibility
With a focus on speed and nimbleness, Agile is open to changes that inevitably arise throughout the
development cycle. The iterative process is flexible, based on an understanding that original requirements may
(or will likely) need to change due to customer demand, market conditions, or other reasons. Because business
users are involved throughout the process, and because each iteration is short, new requirements can be
introduced and prioritized very quickly.
Continuous improvement
An Agile environment provides developers with an opportunity to learn new skills and to exercise greater
autonomy to do their jobs. The iterative framework is empowering because it enables continuous improvement,
with testing/quality assurance occurring as part of the iterative process, rather than only periodically or at the
end of a long process when it is often difficult or not cost effective to fix coding defects or to incorporate lessons
learned along the way. Agile also makes the testing and QA process transparent to the developers who originate
the code, further contributing to their learning and facilitating future improvements and coding efficiencies.
roguewave.com 3
STATIC CODE ANALYSIS IN AN AGILE WORLD
This principle is not unique to Agile — many software development processes, including formal ones such as
CMMI and Six Sigma, encourage the creation of bug-free code as a fundamental principle. These processes
encourage in-phase bug containment — the practice of preventing bugs from being passed downstream from
the phase in which they are created (Figure 1). Agile also implicitly emphasizes in-phase bug containment.
Given its focus on short iterations, Agile processes must ensure that any potential software degradations are
quickly identified and corrected so that the whole team can move on to the next iteration — all while creating
functionally complete, working software.
Even within an iteration, Agile teams apply this philosophy through continuous integrations and regressions.
While this practice effectively addresses defects that can break builds or regression test suites, it is not as
effective in cleaning up many of the most common types of programming bugs, which generally fall into these
broad categories:
roguewave.com 4
STATIC CODE ANALYSIS IN AN AGILE WORLD
Bug-filled code creates downstream risk both within an iteration and in subsequent iterations, in the form of bug
debt. If code flaws are not addressed within the iteration, they pass from one milestone to the next, and the bug
debt accumulates downstream. Bug debt can kill Agile projects by reducing development velocity which leads to
poor implementation results and fewer impactful changes being delivered per iteration. Additionally, bugs that
are saved up (or which go completely undetected until further downstream) are more expensive and often more
difficult to fix, and can lead to products that fail in the field, disappoint customers, and damage the brand.
It is for these reasons that in-phase bug containment is vital to the Agile process. Developers must take control
of the bug identification and removal process while enhancing collaboration amongst themselves to resolve
bugs as early in the process as possible.
• Code reuse
Accepted as an industry best practice, code reuse speeds time to market by increasing development
efficiencies while minimizing the costs associated with net-new development. It also enables development
organizations to leverage the lessons learned from an existing code base. However, merging that code
with new systems can lead to unexpected results.
• Multiple coders
Code bases don’t live and die within a single version or a single iteration, and in an Agile process it is
quite likely that a developer will be editing code that they did not originally create. Inheriting modules
means developers are unfamiliar with the original intent of the code, its variables, and the language
constructs used.
These factors are each contributing to the overall complexity of code bases, which in turn complicates the
software development process. This complexity can lead to slipped release schedules, increased defect rates,
and decreased productivity as more time is taken to accomplish simple, everyday tasks. Development teams
should be vigilant in watching for these signs which indicate code complexity is becoming an issue.
roguewave.com 5
STATIC CODE ANALYSIS IN AN AGILE WORLD
With software, you can monitor the complexity of software builds using industry known metrics. For example,
you can start monitoring your McCabe’s Cyclometic complexity every build. This measurement shows you how
“off” you are from the standard. (McCabe’s complexity dictates anything over a value of 20 as very complex.)
More importantly, teams should be monitoring the trend of that metric. Seeing a large spike with one version
versus the previous might be evidence that complexity issues are impacting your process.
Tracking these metrics in order to identify opportunities to reduce complexity and make code more
maintainable (regardless of who is working on it) should be considered. Not addressing code complexity will
have a negative impact on the velocity of a software project — which can spell disaster in an Agile development
environment.
Figure 2: Monitoring key software metrics, such as the complexity of software builds, helps teams identify and correct
issues impacting the development process.
Take peer code review, for example. The value of code review is unarguable, which explains why they’re
mandated by 53 percent of today’s software development teams.1 However, in an Agile context, traditional
code reviews — scheduling in-person meetings with senior development staff — are highly ineffective and time
consuming. These types of traditional processes need to be adapted so that development teams can continue
to benefit from them without sacrificing development velocity.
1
The Value and Importance of Code Reviews, a commissioned study conducted by
Forrester Consulting on behalf of Klocwork, February 2010.
roguewave.com 6
STATIC CODE ANALYSIS IN AN AGILE WORLD
Unfortunately, most of the tools being used are for managing some aspect of the production process and
are not targeted at helping developers overcome the obstacles they face during the coding phase. Deploying
a properly-selected set of developer-focused tools can help ensure high-quality code is output early in the
development process. The latest evolution of source code analysis technology — combining sophisticated bug
detection with collaborative peer code review and automated code refactoring — can help development teams
avoid bug debt and code maintainability issues, greasing the wheels to achieving an effective Agile process.
The underlying technology associated with SCA is called static analysis and the current generation of technology
solutions are capable of providing sophisticated, high-value analysis that will locate and describe areas of
weakness in software source code — such as memory and resource management, program data management,
buffer overflows, un-validated user input, vulnerable coding practices, concurrency violations, and a variety
of longer term maintenance issues. SCA is distinct from traditional dynamic analysis techniques, such as unit
or penetration tests, because the work is performed at build time using only the source code of the program
or module in question. The results reported are therefore generated from a complete view of every possible
execution path, rather than some aspect of a limited, observed runtime behavior.
Since SCA is essentially a build-time analysis, it is most effectively used as a build milestone activity when
individual developers or development teams run their builds — either at the integration-build level or the
developer-build level.
To make it all work, and to reduce the number of “false positives” (bugs that the tool incorrectly reports) and
false negatives (bugs that the tool misses), vendors naturally provide integration with a project’s system
build — whether it is make, ant, Visual Studio, or other continuous integration tools such as Electric Cloud
roguewave.com 7
STATIC CODE ANALYSIS IN AN AGILE WORLD
and BuildForge — to generate a complete view of the entire source code base. Of course, the downside to
running SCA exclusively at the integration build level is that bugs created at the desktop are exposed to the
main code stream and can impact other members of the team — both fellow developers and the QA team.
When bugs are found downstream — even in a continuous integration context where integration builds are run
much more frequently — an additional bug triaging process needs to be put in place to notify the developer of
the error (by email, web reports, etc.). This adds more workflow and process, which is contrary to the spirit of
Agile development.
Clearly, the solution is to push SCA to the developer desktop so that it can run in conjunction with a developer’s
build, even prior to him/her running unit tests.
For SCA to operate at the developer desktop, it must be delivered within the developer’s natural work
environment (i.e. a favorite IDE, text editor, or command line) and the analysis must be every bit as accurate
and intelligent as the centralized analysis that benefits from a view of the entire code stream. Code check-in (or
commit) is an important milestone in Agile and many organizations operating in a continuous integration context
have a series of gates (smoke tests, unit tests, etc.) that the developer must pass in order for him/her to check-in
code. SCA should be added to this series of pre check-in quality gates.
If organizations embrace SCA with the goal of in-phase bug containment, the key principles of Agile outlined at
the beginning of this paper will be fully realized.
• Code reviews create consistency and a culture of quality for a development team. Identifying bugs and
design flaws while ensuring coding standards and best practices are met means a higher quality product
goes out the door.
• Developers learn from code reviews by having more experienced team members review their code and
provide feedback.
In an Agile context, these benefits are important. However, the traditional method of conducting code reviews
— scheduling in person meetings — is not effective in an Agile context. Agile teams wanting to make code
review part of their process should consider SCA tools with built-in code review capabilities. These tools facilitate
simple, web-based peer review that allows code to be reviewed asynchronously. This approach avoids the need
to get a specific group of people in a conference room at a set time to review code. Instead, code is available
roguewave.com 8
STATIC CODE ANALYSIS IN AN AGILE WORLD
to a variety of team members — regardless of geographic location, calendar availability, and title — to review
and provide feedback on at their convenience. When peer code review capabilities are combined with source
code analysis, coding defects are identified so that reviewers can see them, comment on them, and assign
actions as required.
Martin Fowler, one of the original authors of the Agile Manifesto, describes refactoring as a series of small,
almost negligible changes to code, that when combined, result in a significant end result. Some of the areas
that refactoring has an impact on include:
• Adapting to change
Ongoing change is a fundamental aspect of Agile. By incorporating frequent refactoring into the
development process, code becomes easier to work with which allows teams to adapt to change
more effectively.
• Defect detection
By simplifying code and improving its overall design, code becomes clearer. Working with clean code
makes spotting quality defects and security vulnerabilities easier. And the sooner defects are found
and fixed, the less impact (i.e. distracting developers, bogging down test teams, slowing down the
overall process) they have on the process.
• Developer productivity
Frequently, different people will end up working on code that they did not originally create. With
refactoring, code becomes easier to inherit, which means developers won’t waste iterations reviewing,
interpreting, and fixing existing code and instead focus more time on writing new code.
Clearly, refactoring has an important role to play in helping teams achieve agility. With today’s source code
analysis tools which offer built-in refactoring capabilities, Agile teams can automate the refactoring process to
reduce the complexity around the process while reaping the rewards it has to offer.
roguewave.com 9
STATIC CODE ANALYSIS IN AN AGILE WORLD
With few bugs to find or report on, testers are able to focus instead on running functional and performance
tests to ensure the product is customer- and market-ready.
roguewave.com 10
STATIC CODE ANALYSIS IN AN AGILE WORLD
Figure 3: On-the-fly desktop analysis allows developers to find and fix critical coding issues before code check-in
from within their IDEs. This reduces the time developers have to spend going back and fixing issues not
detected until late in the dev process.
roguewave.com 11
STATIC CODE ANALYSIS IN AN AGILE WORLD
Figure 4: Klocwork automatically generates rich reporting that allows Agile teams to monitor the health of their
integration builds, along with tracking desktop bug fix rates.
roguewave.com 12
STATIC CODE ANALYSIS IN AN AGILE WORLD
Figure 5: With Klocwork, refactoring options are available right within your editor, allowing you to improve code design
without having to access separate views or dialogs.
CONCLUSION
The ubiquitous nature of software today, coupled with the pressure to rapidly develop market-ready features
and products in just weeks, has led to two related phenomena:
Some of the most important types of tools that an Agile team can deploy are ones that aid in writing better-
quality code. SCA tools provide an automated method to detect a significant number of software bugs and
security vulnerabilities right at the developer’s desktop — before any code is delivered to the integration build
or testing team. Combine that with automated refactoring to ensure more maintainable code, and an Agile
team can minimize project drag and run more efficiently overall. Developers can focus their time writing
innovative code, while testing teams spend their time testing how the features of the project work rather
than uncovering mundane code issues and retesting these again and again.
roguewave.com 13
STATIC CODE ANALYSIS IN AN AGILE WORLD
SCA may be right for your Agile team, particularly if you are finding your process being impacted by quality issues
or security vulnerabilities, non-Agile friendly processes, and hard to maintain code. Implementing source code
analysis within your Agile environment does not have to be disruptive. You can start small and analyze only a
small project or a portion of a project. Compare the results against a similar project where these tools were
not used. You’ll undoubtedly find opportunities to save significant time and money by using SCA in your Agile
development process.
Rogue Wave helps thousands of global enterprise customers tackle the hardest and most complex issues in
building, connecting, and securing applications. Since 1989, our platforms, tools, components, and support have
been used across financial services, technology, healthcare, government, entertainment, and manufacturing, to
deliver value and reduce risk. From API management, web and mobile, embeddable analytics, static and dynamic
analysis to open source support, we have the software essentials to innovate with confidence. roguewave.com
roguewave.com 14