Static Analysis Isn’t Just for Techies
Think static analysis is solely useful for techies and their code? Think again.
Join the DZone community and get the full member experience.Join For Free
i do a lot of work with and around static analysis tools. i also have a consulting practice that includes detailed codebase and team fact-finding missions, and i have employed static analysis aplenty when i’ve had run of the mill architect gigs. doing all of this, i’ve noticed that the practice gets a rap of being just for techies.
beyond that, even, people seem to perceive static analysis as the province of the uber-techie: architects, experts, and code statistics nerds. developing software is for people with bachelors’ degrees in programming, but static analysis is ph.d.-level stuff. static analysis nerds go off, dream up metrics, and roll them out for measurement of developers and codebases.
this characterization makes me sad — doubly so when i see something like test coverage or cyclomatic complexity being used as a cudgel to bonk programmers into certain predictable behaviors. at its core, static analysis is not about standards compliance or behavior modification, though it can be used for those things. static analysis is about something far more fundamental: furnishing data and information about the codebase (without running the code). wanting information about the code is clearly something everyone on or around the team is interested in.
to drive this point home, i’d like to cite some examples of less commonly known value propositions for static analysis within a software group. granted, all of these require a more indirect route than, say, “install the tool and see what warnings pop up,” but they’re all there for the realizing (if you’re so inclined). one of the main reasons that static analysis can be so powerful is scale — tools can analyze 10 million lines of code in minutes, whereas a human would need months.
one of the most “human element” type of benefits that i’ve seen for static analysis can come in the form of dispute resolution. if two people or two camps of people on a team are at odds over some particular practice or style of coding, static analysis tools can serve as mute, disinterested arbitrators. should you avoid the singleton design pattern or is it the greatest thing since sliced bread? if you’re at a log jam on this one, perhaps you can defer to ndepend’s “avoid the singleton pattern” warning that comes out of the box.
please note that i am not suggesting that you should blindly follow the advice of a tool, nor that the tools are infallible. the purpose of the arbitration process is to offer a way for a credible source to settle disputes, and static analysis tools can serve in this capacity, at least for some issues.
help with morale
this may sound strange at first, but static analysis tools can actually be a source of morale for some teams. to understand how, consider the wisdom of the aphorism, “sunlight is the best antiseptic,” meaning that just revealing a problem makes its solution more likely. a software group may be struggling with all sorts of problems that are not common knowledge, but you can bet the developers understand and live them, even if not explicitly. for instance, consider a codebase with crippling and bad technical debt.
the mere presence of static analysis tools will serve to indicate two things to the development group: the business is aware of the problems and the business is willing to spend time and money on fixing them. that alone can be a surprisingly large morale boost for a team in a rut.
definition of department or team goals
with such tooling in place, the next major benefit i’ll talk about comes from using the tooling to define goals. this is important and not to be confused with letting tool compliance actually be your goal. i’m not talking about downloading a tool that says you have too many lines of code per method and then adopting “make the warning go away” as your goal (there’s nothing wrong with this, per se — it’s just not what i’m talking about here).
instead, use the tools to explore your code, looking for themes and common problems. enlist team members to talk anecdotally about issues that they have and what holds up the development process. bring these two approaches together and use the static analysis tooling to gather data about problems and then propose solutions — solutions that are measurable.
i’ve heard it said that if you want to improve, the first step is figuring out what to measure. that’s what i’m talking about here — use the static analysis tooling to help you figure out what to measure and then to measure it.
validate or refute business hypotheses
moving away from team-focused benefits, we can also talk about the business as a whole. one of the main communication difficulties with software generally is the unavoidable boundary between the people writing the software and everyone else. that delivery team understands the reality of the code at a nuts and bolts level, but everyone outside of the delivery team understands the code only through anecdotes (“oh, man, we can’t touch the invoicing module because it’s terrible legacy code!”) or downstream qualitative outcomes (“this release must be a bad one because we’re getting more complaints than usual.”)
static analysis tooling can bridge this gap to an extent, and furnish data to interested parties outside of the delivery team. i cannot understate the importance of this capability. it allows the formation of a hypothesis like, “i think the team writes better code when they aren’t logging significant overtime,” and then to empirically compare code written during lulls and rushes for certain properties. that is powerful!
predict business outcomes
if you’re willing to continue in the same vein and to get a little bit more speculative, you can start to make predictions. after all, this is classic scientific method stuff. in the last part, i mentioned hypotheses confirmation or refutation, but you need hypotheses to do that in the first place. while a hypothesis and a prediction are not the same, if you get good enough at formulating and verifying hypotheses, you start to develop a better prediction framework.
to get a little more concrete about it, consider a situation where you run experiments correlating properties of different codebases in your portfolio with each application’s defect rate. if you find a strong correlation between global state and high defects, it might be reasonable to predict a lower defect rate for a future release that involved no global state.
broader thinking with static analysis
these are just some benefits that occur to me off of the top of my head. no doubt other static analysis veterans could think of plenty of additional uses besides. you’ll notice that nothing mentioned here includes anything about compiler design, logic theory, or anything else intimidating.
static analysis is a topic that delves into the highly technical, to be sure. analyzing source code for patterns and predictors is not for the faint of heart, to be sure. remember that, at the end of the day, it can be used for all sorts of purposes, highly technical and highly approachable. after all, static analysis is really about producing data.
Published at DZone with permission of , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.