Making Stuff Faster
Design, Code, Database Performance

How unique is your code?

Thursday, November 03, 2005 10:28 AM

Recently I found a tool that will parse a .Net assembly(s) and return back an object graph of the underlying structure: Assemblies, Namespaces, Types, Members...all the way down to the IL opcodes in each method.

This opens a lot of doors to writing tools that can look at the overall architecture of your application, across many assemblies.  One tool I wrote creates a MD5 hash of the contents of each method, based on the IL opcodes and the values they are operating on.  From this I can then figure out which functions are exact duplicates of other functions in your code (Steven Mcconnell once said that copy/pasted code is a design flaw).

So I ran the tool on one of my applications and came up with a lot of duplicate functions.  But after looking at them I realized almost all were one line property getters, that were returning a private field.  The other culprit was default constructors that get generated for you by the compiler if you don't have one, or if you have an empty one.  Once I weeded these culprits out of the analysis, I came up with very few duplicated functions.

Then, just for fun, I sicked my tool on Microsoft's System.dll to see how original their programmers were.  Turned out i found 88 duplicate functions.  That means there were 176 functions that shared code with another function.


Feedback

# re: How unique is your code?

Can you please post your code and link to the tool you are using 11/4/2005 4:36 AM | Manolo

# re: How unique is your code?

nice to hear news from u dude! 3/23/2006 1:10 AM | mp3

Post a comment