views:

237

answers:

8

How would you define "unwanted code"?


Edit:

IMHO, Any code member with 0 active calling members (checked recursively) is unwanted code. (functions, methods, properties, variables are members)

+1  A: 

Like you said in the other thread, code that is not used anywhere at all is pretty much unwanted. As for how to find it I'd suggest FindBugs or CheckStyle if you were using Java, for example, since these tools check to see if a function is used anywhere and marks it as non-used if it isn't. Very nice for getting rid of unnecessary weight.

Stefan Thyberg
+1  A: 

Well after shortly thinking about it I came up with these three points:

  • it can be code that should be refactored
  • it can be code that is not called any more (leftovers from earlier versions)
  • it can be code that does not apply to your style-guide and way-of-coding

I bet there is a lot more but, that's how I'd define unwanted code.

Gambrinus
+1  A: 

In java i'd mark the method or class with @Deprecated.

emeraldjava
+1  A: 

Any PRIVATE code member with no active calling members (checked recursively). Otherwise you do not know if your code is not used out of your scope analysis.

madgnome
A: 

Usually I tell my compiler to be as annoyingly noisy as possible, that picks 60% of stuff that I need to examine. Unused functions that are months old (after checking with the VCS) usually get ousted, unless their author tells me when they'll actually be used. Stuff missing prototypes is also instantly suspect.

I think trying to implement automated house cleaning is like trying to make a USB device that guarantees that you 'safely' play Russian Roulette.

The hardest part to check are components added to the build system, few people notice those and unused kludges are left to gather moss.

Beyond that, I typically WANT the code, I just want its author to refactor it a bit and make their style the same as the rest of the project.

Another helpful tool is Doxygen, which does help you (visually) see relations in the source tree.. however, if its set at not extracting static symbols / objects, its not going to be very thorough.

Tim Post
+2  A: 

Here's my definition of unwanted code:

  • A code that does not execute is a dead weight. (Unless it's a [malicious] payload for your actual code, but that's another story :-))
  • A code that repeats multiple times is increasing the cost of the product.
  • A code that cannot be regression tested is increasing the cost of the product as well.

You can either remove such code or refactor it, but you don't want to keep it as it is around.

Franci Penov
Do people ever lay down a generous payload in code or is that only in the smallest room in the house?
random
@Random Echo - I've seen generous code payload only in one project so far. so I agree it's extremely rare scenario.
Franci Penov
+1  A: 

0 active calls and no possibility of use in near future. And I prefer to never comment out anything in case I need for it later since I use SVN (source control).

cherouvim
A: 

Some things are already posted but here's another: Functions that almost do the same thing. (only a small variable change and therefore the whole functions is copy pasted and that variable is changed)

PoweRoy