tags:

views:

450

answers:

7

Hear lately I've been listening to Jeff Atwood and Joel Spolsky's radio show and they have been talking about dogfooding (the process of reusing your own code, see Jeff Atwood's blog post). So my question is should programmers use decompilers to see how that programmers code is implemented and works, to make sure it won't break your code. Or should you just trust that programmers code and adapt to it because using decompilers go against everything we as programmers have ever learn about hiding data (well OO programmers at least)?

Note: I wasn't sure which tags this would go under so feel free to retag it.

Edit: Just to clarify I was asking about decompilers as a last resort, say you can't get the source code for some reason. Sorry, I should have supplied this in the original question.

+4  A: 

Dogfooding is the process of using the code that you write, not necessarily re-using code.

However, code re-use typically means you have the source, hence 'code-reuse' otherwise its just using a library supplied by someone else.

Decompiling is hard to get right, and the output is typically very hard to follow.

gbrandt
Of course, if you write library code, then dog fooding *is* using your own API.
Software Monkey
right, but then you don't need to decompile it.
gbrandt
+1  A: 

You should use a decompiler if it is the tool that's required to get the job done. However, I don't think it's the proper use of a decompiler to get an idea of how well the code which is being decompiled was written. Depending on the language you use, the decompiled code can be very different from the code which was actually written. If you want to see some real code, look at open source code. If you want to see the code of some particular product, it's probably better to try to get access to the actual code through some legal means.

Kibbee
+1  A: 

I'm not sure what exactly it is you are asking, what you expect "decompilers" to show you, or what this has to do with Atwood and Spolsky, or what the question is exactly. If you're programming to public interfaces then why would you need to see the original source of the the third party code to see if it will "break" your code? You could more effectively build tests to in order to determine this. As well, what the "decompiler" will tell you largely depends on the language/platform the software was written in, whether it is Java, .NET, C and so forth. It's not the same as having the original source to read, even in the case of .NET assemblies. Anyway, if you are worried about third party code not working for you then you should really be doing typical kinds of unit tests against the code rather than trying to "decompile" it. As far as whether you "should," if you mean whether you "should" in some other way other than what would be the best use of your time then I'm not sure what you mean.

BobbyShaftoe
+1  A: 

Should Programmers Use Decompilers?

Use the right tool for the right job. Decompilers don't often produce results that are easy to understand, but sometimes they are what's needed.

should programmers use decompilers to see how that programmers code is implemented and works, to make sure it won't break your code.

No, not unless you find a problem and need support. In general you don't use it if you don't trust it, and if you have to use it you even when you don't trust it you develop tests to prove the functionality and verify that later upgrades still work as expected.

Don't use functionality you don't test, unless you have very good support or a relationship of trust.

Adam Davis
+5  A: 

Yes, It can be useful to use the output of a decompiler, but not for what you suggest. The output of a compiler doesn't ever look much like what a human would write (except when it does.) It can't tell you why the code does what it does, or what a particular variable should mean. It's unlikely to be worth the trouble to do this unless you already have the source.

If you do have the source, then there are lots of good reasons to use a decompiler in your development process.

Most often, the reasons for using the output of a decompiler is to better optimize code. Sometimes, with high optimization settings, a compiler will just get it wrong. This can be almost impossible to sort out in some cases without comparing the output of the compiler at different levels of optimization.

Other times, when trying to squeeze the most performance out of a very hot code path, a developer can try arranging their code in a few different ways and compare the compiled results. As a last resort, this may be the simplest way to start when implementing a code block in assembly language, by duplicating the compiler's output.

TokenMacGuy
Strange answer. A decompiler is not used to check if optimizations are done correctly by a compiler. You just use the assembly output generated by the compiler for this. Decompilers are traditionally used to generate highlevel source/concepts back from machinecode. However, unless you are using unubfuscated java or c#, the results are highly dissapointing.
Toad
@reinier: decompiled code is, exactly as you say, disappointing. The answer I tried to give was mostly about what you actually can do with a decompiler.
TokenMacGuy
+1  A: 

Or should you just trust that programmers code and adapt to it because using decompilers go against everything we as programmers have ever learn about hiding data (well OO programmers at least)?

This is not true at all. You would use a decompiler not because you want to get around any sort of abstraction, encapsulation, or defeat OO principles, but because you want to understand why the code is behaving the way it is better.

Sometimes you need to use a decompiler (or in the Java world, a bytecode viewer) when you are troubleshooting an annoying bug with a 3rd party library where an exception is thrown with no useful error message, no logging, etc.

Use of a decompiler has nothing to do with OO principles.

matt b
+1  A: 

The short answer to this... Program to a public and documented specification, not to an implementation. Relying on implementation specifics and side-effects will burn you.

Decompilation is not a tool to help you program correctly, though it might, in a pinch, assist you in understanding a problem with someone else's code for which you don't have source.

Also, beware of the possible legal risk of decompiling; many software companies have no-decompile clauses which could expose you and your employer to legal consequences.

Software Monkey