Every now and then, I encounter some complex legacy code that has been moved around and changed so much, git blame doesn’t help in finding the original commit. Git bisect is the solution here. Why the Original Commit Can Help Sometimes, I read code and (after a while) it becomes clear what it does. But I’m often left wondering why the code is there, what the context was. It allows me to read the commit message and maybe several commits

While working on a legacy application for a client, I wanted to get some code coverage for my tests. In Python, this usually means running Coverage.py and pointing it to your unit tests. This being a legacy application, there were no unit tests. There were Postman tests however. This is a simple technique that is useful when working with legacy applications. The idea is simple: we run our application using Coverage.py. The application is a Django application and so it

There’s a Catch-22 hidden in the arguments that many people use to rationalize not writing tests. The Catch A Catch-22 is a situation that you can’t escape out of due to contradictory rules or limitations. In case of automated tests for software, the arguments often go like this. At the start of the project, both developers and managers say that the project is too young and changing all the time. There’s also market pressure to get something minimal out there

Here I am again with a follow up post in my series on fixing a real world legacy application. I’ve been continuing my work with NDepend and wanted to give an update on what it has helped me do. Just a small reminder: the application is a web application to make forecasts about the World or European championship football/soccer. You can read more about it in my first post. Mutable Statics I had a large class containing all the teams

In my series of fixing a real-world legacy application, I’ve already improved the code in some big blocks: updated Bootstrap introduced dependency injection removed unnecessary cruft added logging But fixing legacy applications often means making many smaller improvements. Many of these are often a matter of personal opinion. And when multiple developers do agree on an issue, they might not agree on a particular solution. The best way to avoid these nonconstructive discussions, is to have a tool to automate

I’ve written multiple posts about legacy code and automated tests. I believed both are closely connected in that one can help solve the other. I also enjoy working on legacy code, improving software development practices and improving code quality. But this blog has always been geared towards developers, and it seems managers don’t always follow. Which is why I’ve started a new blog, aimed at managers dealing with legacy code. Over time, I’ve come to like improving the situation around

This application contains absolutely no logging. In many legacy enterprise application, there usually is some logging, but it’s often not very useful. In some cases, there is no logging at all. This makes it hard to troubleshoot when things go wrong. In .NET, the first logging frameworks that come to many developer’s minds is log4net or NLog. I’d recommend NLog over log4net because the documentation seems better to me. In my position as consultant, I often encounter custom logging frameworks.

Continuing my series on fixing my real-world legacy application, I will now introduce dependency injection. First, I simply installed the Autofac.Mvc5, Autofac.Mvc5.Owin and Autofac.WebApi2.Owin NuGet packages. This changes nothing of course. So next, we tell ASP.NET to let Autofac handle the creation of the controllers. In our Startup class, we add: This is basically what’s in the Autofac documentation. Notice how we need to set up Autofac for both MVC and WebAPI. This is because this application is using both. I’m using

When I first started writing this app, I wanted to move fast. I found a JavaScript library that promised to connect my client-side code to my Entity Framework context very easily: Breeze. For some reason that I can’t remember now, I never ended up using very much of it, if anything at all. But I had never cleaned up the mess I had left behind. This is a typical example of how legacy code accumulates: components get added for small