What Makes a Codebase Acquirable?
Tags: career, dotnet, ndepend
Published: 2020-03-26 14:16:50

---
title: What Makes a Codebase Acquirable? 
published: true
description: Has you ever inherited a codebase your company acquired? That can be a nightmare or it can be fine. How do you know which?
tags: #career #dotnet #ndepend
canonical_url: https://blog.ndepend.com/what-makes-codebase-acquirable/
---
<em>I originally <a href="https://blog.ndepend.com/what-makes-codebase-acquirable/">posted this on the NDepend blog</a> a little under two years ago. < <a href="https://www.ndepend.com/">NDepend</a> is a static analysis tool that plugs right into Visual Studio.</em>

What makes a codebase acquirable?

This is the rare question that affects software developers, managers, and executives in a surprisingly similar way.  And that's saying something since, by and large, people up and down the corporate pyramid don't tend to share a lot of professional overlap.

<a href="https://blog.ndepend.com/wp-content/uploads/What_Makes_a_Codebase_Acquirable.png"><img class="wp-image-8295 size-full aligncenter" src="https://blog.ndepend.com/wp-content/uploads/What_Makes_a_Codebase_Acquirable.png" width="650" height="777" /></a>

<h2>Codebase Acquirability: The Developer's Story</h2>
Early in my career, about 100 years ago, my company acquired a small mom-and-pop operation.

Mom and pop had built a niche, feature-rich accounting package that helped my employer's customers.  And they built it in MS Access, of all things.  (Neither mom nor pop was a software professional by trade, so this was a self-taught, learn-on-the-fly situation where, all things considered, they did something impressive.)

Of course, I wasn't part of this acquisition.  My job title at the time was, to the best of my recollection, "software engineer."

So I first encountered this MS Access codebase (which is technically just a file) during a meeting with my boss and the VP of engineering.  "Congratulations, Erik," they told me.  "You're now the tech lead for this product."

Here's the MDB file, so go put it in source control or whatever, and try to make it into something that looks like it actually belongs in our application portfolio."  The glass-half-full interpretation of my reaction was "wow, you're putting a lot of faith in me."

Had I been part of the acquisition discussion, I'd have thrown red flags like a bullfighter.  But I wasn't.  We acquired the code and it worked out.
<h2>Codebase Acquirability: The Executive's Story</h2>
But you know who is part of the acquisition discussion?  Executives.

And they worry just as much about the nature of acquired codebases as the prospective developers working in them.  A gigantic mess of a codebase is unpleasant for the folks working in it and problematic for achieving business goals.

In more recent years as a consultant, I've helped executives face strategic decisions about codebases.
<ul>
 	<li>Should I retire this or keep plugging away?</li>
 	<li>Can we evolve this codebase to keep up with the current market?</li>
</ul>
And, yes, there were questions of what to do with inherited codebases or whether or not <em>to </em>inherit them.

But how does one actually make that determination?  Do you send in a few software developers to size the thing up and give you anecdotal "expert" opinions?

I mean, you <em>can</em>, and that's better than nothing at all.  But it's some kind of law of nature that we software developers hate any code that we didn't write.

So how do you really know?  How do you tell if a codebase is acquirable?
<h2>First of All, What Do Acquiring Shops Do With New Codebases</h2>
Reasoning about codebase acquirability can initially feel like boiling the ocean.  You might be looking to take on a codebase with hundreds of thousands or millions of lines of code.

Even if the party from whom you were acquiring the thing were to give you endless time and access, you might be poking around for months.

And the problem itself seems a little hard to wrap your head around.  Isn't this just the same as asking, "is this code 'good' for some definition of good?"

Admittedly, it's not easy to tease out a working way to evaluate acquirability.  But it's not impossible, either.  Consider some things that organizations will typically do when they acquire a codebase:
<ul>
 	<li>Re-brand or overhaul the GUI in some fashion</li>
 	<li>Perform various flavors of service or database migration</li>
 	<li>Assign new people to work on it</li>
 	<li>Merge it with another codebase</li>
 	<li>Evolve it to keep up with market concerns</li>
 	<li>Leave it alone and touch it as little as humanly possible</li>
</ul>
<h2>Reasoning About Acquirability</h2>
And that leads us to be able to define some questions to ask about a new codebase.  With these potential activities in mind, let's look at some code-specific questions that we might ask.
<ul>
 	<li>Re-brand or overhaul the GUI in some fashion: <strong>how coupled are the GUI and the application code</strong>?</li>
 	<li>Perform various flavors of service or database migration: <strong>what is the general level of coupling in this codebase?</strong></li>
 	<li>Assign new people to work on it: <strong>how easily groked ("clean") is this codebase?</strong></li>
 	<li>Merge it with another codebase: <strong>how modular is this code, and how much does it conform to standard practices?</strong></li>
 	<li>Evolve it to keep up with market concerns: <strong>what kind of test coverage and quality of unit tests are there and how much <a href="https://blog.ndepend.com/exploring-technical-debt-codebase/">tech debt</a> is there?</strong></li>
 	<li>Leave it alone and touch it as little as humanly possible: <strong>how buggy does this code figure to be?</strong></li>
</ul>
Now, this is neither an exhaustive list, nor will you probably want to do <em>all </em>of these things with the incoming codebase (indeed, "evolve and leave it alone" simultaneously wouldn't even be possible).  But it backs us away from boiling the ocean.

It's a start.

The question now is how do you go about answering these questions?
<h2>NDepend and Acquirability Out-of-the-Box</h2>
As I've said before, I have a consulting practice wherein I help executives answer questions like these.  But I don't think I'd be giving away the slightest bit of tradecraft to say that I use NDepend prominently in performing codebase assessments.

Let's consider some out-of-the-box properties of taking this approach.  In <a href="https://blog.ndepend.com/moq-code-quality/">a post I did about analyzing the Moq codebase</a>, I talked about the codebase's tech debt grade and the reasoning behind it.

If you're looking to see how easily a codebase will evolve, that's an excellent starting point right there on the dashboard.  You can go in and see the debt and then drill into the reasoning behind it  You can also bring in test coverage data to get a comprehensive answer to the evolution question.

From there, you can take a more detailed tour through <a href="https://www.ndepend.com/docs/critical-cqlinq-rule">the out-of-the-box code rules</a>.  If NDepend is showing you critical rule violations galore, code smells, design issues, and regressions, you can assume that you're looking at a potentially buggy codebase and one that won't conform to standard practice.

And then, for questions of modularity and coupling, you can simply <em>look</em> at the codebase via detailed dependency graphs.  If you're more of a numbers person, you can have that too, but when it comes to architecture, <a href="https://blog.ndepend.com/visualizing-software-architecture/">a picture is worth 1,000 words</a>.

So with a quick install and analysis from NDepend, you can start to put together pretty compelling and visual answers to these questions.
<h2>Making the Case With CQLinq</h2>
Notice that I talked about the quality of unit tests and also the reliance specifically on GUI-based libraries.  In this case, you're asking questions that are a little more specific than the ones that NDepend's default rules answer right out of the box.

But that's where <a href="https://www.ndepend.com/docs/cqlinq-features">CQLinq</a> really shines.  With CQLinq, you can turn the <a href="https://blog.ndepend.com/static-analysis-code-as-data/">code into data</a>, and you can answer just about any question you want.

For instance, what is a well-written unit test?  Well, that's hard to say at a glance.

But figure that it probably doesn't have excessive setup and that it probably asserts something.  So you can put together a CQLinq query to see what percentage of unit tests have fewer than say 10 lines of code and that have at least one assert.

That's not definitive, but if a low percentage of the tests meet those criteria, you might be looking at an iffy test suite, coverage notwithstanding.

You can also enlist CQLinq in this fashion to zero in on specific dependencies.  See how many of your classes contain direct references to some GUI assembly.  Or see what percentage of your codebases's references are to relatively common libraries and how many oddball utilities are in there.

This isn't an exhaustive list of what you can evaluate by any stretch, but it conveys an idea of what's possible.
<h2>You Actually Can Look Before You Leap</h2>
I could write a whitepaper or even a book about evaluating a codebase's suitability for acquisition.  (I might actually do that at some point, come to think of it.)

But you don't need all of that information to understand the salient point here: evaluating a codebase in this way isn't beyond you, even with relatively limited exposure to the codebase.

Is it daunting?  Sure.

Is using a tool to look at hundreds of thousands of lines potentially reductionist?  Of course—how else could you look at so much code so quickly?

But is it valuable?  Absolutely.

Thinking back to having an MS Access database plopped in my lap, I can't help but wonder if, armed with good tooling and the ability to make a persuasive business case, I might have helped change the trajectory of that business decision in a way that benefited everyone.

<em>If you want to take a Freakonomics style look at your codebase by turning code into data, you can <a href="https://www.ndepend.com/downloadcn?utm=blog">take NDepend for a 14 day spin</a>.</em>