Iris Classon
Iris Classon - In Love with Code

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

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).

[caption id=“attachment_8972” align=“aligncenter” width=“675”] Intellitrace- image shamelessly stolen from MS documentation ;) Intellitrace- image shamelessly stolen from MS documentation ;)[/caption]

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.

[caption id=“attachment_8982” align=“aligncenter” width=“864”] Comparing files in PowerShell Comparing files in PowerShell[/caption]

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 :)

 

Comments

Leave a comment below, or by email.
Bogdan
10/26/2013 11:49:19 PM
Uncle Bob says that good programmers don't debug their code, because TDD eliminates this need ;) 
JohnJohn Marshall
10/27/2013 7:22:37 AM
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. 
Mata
10/29/2013 7:24:40 AM
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. 
ätobbe
11/16/2013 1:33:31 PM
I use Notepad++ with the plugin "Compare". Works like a charm for me! ;) 
Mark Conway
12/24/2013 9:55:45 PM
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. 


Last modified on 2013-10-24

comments powered by Disqus