Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Code refactoring

mycoffeeAug 5 2014 — edited Aug 11 2014

Hell code refactoring!

I inhirite a Java application that was written 15 years ago with millions lines of code

The code has many problems, including some very basic stuff like comparing object using ==. But somehow, it works and the company keeps using it

The problem we are facing is the code doesn't support debugging. ALL of the methods have very limited number of variables. The coders writting something like this all over places

if(getA().getB().getC().getD().getE().getM().equals(getA().getB().getC().getD().getE().getN()){

     getA().getB().getC().getD().getE().getM().setZ(getA().getB().getC().getD().getE().getN().getZ());

}

int num = getA().getB().getC().getD().getE().getM().getList().size();

for(int i = 0; i<num; i++){

    getA().getB().getC().getD().getE().getM().getList().get(i).setSomething();;

}

It is unbelievable but it is real. Some of them have more than 10 get() on the same line

I try to refactor it, adding local variables into the methods, so we can resuse the objects instead of using lines of get()

It also help debugging the code possible because there are many recursive calls plus the above style make it almost impossible now. Whenever something happens, it took me days to figure out what is wrong

I am going to break the get() chains but since the code base is huge, I don't know if we have some tools availble.

If someone has solved similar problem, please give me some advice.

Thank you very much

This post has been answered by TPD-Opitz on Aug 5 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 8 2014
Added on Aug 5 2014
12 comments
3,229 views