• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to remove old 'if' conditions programatically

 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

We have a large code base and over time we have put lot of 'if' conditions to evaluate condition if a particular site feature should be turned on or off. Obviously after a while either feature was doing good and there was no way going back and 'if' condition always return true OR the feature was scrapped and we don't need the 'if' condition and want to keep 'else' logic. However the code is already in the mess of lot of 'if' (and corresponding 'else').

If it were just my code and few hundred files I'd have done it manually BUT I am talking about huge code base touching many developer's life (who are not even there anymore with the company ).

Is there any systematic way of doing this? Any external tools or research done to figure out and evaluate the runtime of the JVM and suggest which 'ifs' are useless now since they always evaluate to true?

I hope you get what I am asking for, otherwise please let me know and I'll try to be clearer.

Thanks
Maulin
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Automatic way I do not think so.

I think you could remove one by one for properties configurations or so.
 
Paul Clapham
Sheriff
Pie
Posts: 20208
26
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's an old rule in the computing business which says "If it ain't broke, don't fix it".

Even if you are completely certain that a particular feature is no longer in use, there is still a risk in removing it from the code. You might, for example, remove the "if (...) {" part and its associated code, and then remove the wrong closing brace. You would probably have to run the code through the testing and acceptance process again (you said it was a large code base so I'm assuming you have that process).

As for automation: there isn't a program which can analyze a Java class and tell you whether a particular if-clause will be executed. However if you have the same code copied-and-pasted in many places (which does happen even in Java), you could conceivably scan the source code looking for that. And there might be tools to scan the source code to look for frequently-duplicated code. In fact I'm fairly sure there must be, although I can't name them.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm... Thank you all for your responses.
 
Paul Clapham
Sheriff
Pie
Posts: 20208
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maulin Vasavada wrote:


Yes, I agree. Where I work we also have a large codebase with many unused and obsolete features.
 
Jayesh A Lalwani
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can run a code coverage tool and it will tell you which parts of your code aren't being executed. Or you can just use a text search tool like grep to find places where you have used a specific property

Having said that, probably the effort to remove dead code is going to be much larger that finding the dead code.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic