Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Clean code" book question: refactoring always?

 
Rogerio Kioshi
Ranch Hand
Posts: 690
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Many times we get some application whose code is not very well written, but the application is working fine.
Do you think is it a waste of time refactoring something like this, if the whole application was written in a way you consider not so clean?

Thank you.
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMHO, if you have the time, ALWAYS refactor. You would certainly be in the situation where you need to maintain that code, and then you will be in deep S***
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My rule of thumb is (and I think I learned that at least partly from Uncle Bob) that code that I touch should be in a better shape when I'm finished with it then it was before.

Refactoring code that I don't need to touch, or making the code "perfect" immediately can be fun, but often isn't viable economically, and sometimes even risky.
 
Robert Martin
Author
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rogerio Kioshi:
Hi,

Many times we get some application whose code is not very well written, but the application is working fine.
Do you think is it a waste of time refactoring something like this, if the whole application was written in a way you consider not so clean?

Thank you.


It is not a waste of time to refactor ugly code. You don't want to turn that refactoring into a whole project of it's own however. Rather, every time you touch that code, you should clean a little bit of it. Every time you check it in, make sure it's cleaner than when you checked it out. (This is the "Boy Scout Rule").
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic