Oct 242013
 October 24, 2013  Posted by at 8:58 am Not So Stupid Questions, PowerShell  Add comments

As I’m becoming a better programmer (my first year as a programmer) I’m also getting better at debugging, and it is one of my favorite things to do. Yes, I said it, I love debugging.  But then again I love pretty much everything about programming. Anyway. One technique I’ve recently learned to appreciate is differential debugging.

Differential debugging is when you compare a working system or component to a non-working one, either an earlier version or a very similar system or component.

The two systems (I’ll just refer to them as systems, but this includes features and components) can be compared in a few different ways. You can for example, and this is what I have been doing since I haven’t had any log files to compare, step through the code and take notice of differences. If you use intellitrace (which I do, you have an excellent tool of recording the whole process and can even share it with other developers if they need to replicate the debugging).

Intellitrace- image shamelessly stolen from MS documentation ;)

Intellitrace- image shamelessly stolen from MS documentation 😉

When comparing a system with a previous non-defect version (defect or bug?) use the last working one, and if you don’t quite know when it was, skip a few versions back and work your way both forwards and backwards. If current version is 90 start for example at 50 (depending on approx. when you believe it was) and 89 and skip a set amount of versions at the time until you find the working one. You might even settle for a working version that isn’t the closest one, it depends on your problem.

Comparing files in PowerShell

Comparing files in PowerShell

The ideal situation is to have log files, as this allows you to use external tools to compare the two systems. The simplest way to compare could be something as easy as just using the compare-object command in PowerShell, but usually you would create scripts that lets you focus on things such as timestamps, error codes, thread id, assemblies loaded, paths used and so on. If you use Git you can use the git diff command to compare log files, or code files if you already kind of know where the problem lies. Code files however doesn’t provide error information, but at some point you will need to identify the changes made and git diff let’s you do that- and you can take a look at all files in a branch or tag or folder or… you get the picture. Be creative about how you compare, and use the tools you have and know.

And for what I know there might even be some other tools than shells and command lines that you can use as well. Let me know, I’m just starting to learn this 🙂

Let’s consider this blog post a work in progress, this is fairly new to me, so more will be added later 🙂


  5 Responses to “Stupid Question 256-257: What is differential debugging, and how do I compare files in PowerShell?”

  1. Uncle Bob says that good programmers don’t debug their code, because TDD eliminates this need 😉

  2. In the old days I used the Diff command on the VAX. Today I use the Compare Documents feature in Word. You can tell Word to ignore spacing so you only compare content.

  3. Nice introduction. I recommend you try Beyond Compare as it’s only $30 then add it as your default git diff tool or as TFS diff tool. Helped me several times.

  4. I use Notepad++ with the plugin “Compare”. Works like a charm for me! 😉

  5. I think Visual Studio ’13 Compare looks quite pretty and does as much as it needs to. Maybe grab beyond compare if you want to do a full binary compare.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



What is 14 + 3 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)