<< He Invented Ant, But He's Writing Makefiles Now! | Home | Java 7 To Gain Native XML Data Support >>

Does It Work?

This conversation sparked itself spontaneously today:

Jonathan: If you see a piece of ugly code, what do you do?

Me: Does it work?

Jonathan: Yes.

Me: Then let it work.

Jonathan: Then why do we refactor?

Me: Does it work?

Kevin: The meaning of work here is more than correctly executing an algorithm. If a piece of new functionality cannot be easily added, then the code does not "work" in a broader sense.



Re: Does It Work?

I fix ugly code all the time, but generally because I'm working with that code for other reasons, such as adding a new feature or fixing a bug. In a nutshell, don't clean it up until the ugliness actually impacts you. Premature code cleanup might be a waste of time because 2 weeks from now, when the customer asks you to add some new feature, you might find that the code needs to behave differently anyway. Why not just wait until that time to fix the code? It should take you the same amount of time whether you fix it now or then, and "then" you won't be guessing about what features might be needed.

Re: Does It Work?

I'm on the fence with this. Yes, you can ignore ugly code but if the goal of refactoring is to improve the overall design of the codebase and not fix bugs or add features, I would say you can refactor anytime as long as it's not labour intensive and affects those bug fixes or new features.

While premature code cleanup might seem like a waste of time, I don't think you can live by a blanket rule to never do it in case the requirements change a few weeks down the road. They will. And so will your code.

I think a clean codebase that's easy to navigate, manage, etc. without smells that will put off touching it is more adaptive to change. So when that new feature does come along you're not pulling your hair out because the design is ugly.

Of course if all you worry about is "does it work" then we could leave mainframe systems and aging client/server apps that have worked for years alone and never touch them. I don't feel that's a maintainable state to be in.

Re: Does It Work?

I've let code get smelly on almost every project I've worked on. I must admit, I regret it every single time!

The main reason being that often when I want to work with the code again, I don't feel I have the time or inclination to play clean-up. I then end up making the code even more smelly, and over enough iterations that significantly slows me down, and makes my job far less fun.

For any new development work, I'm striving toward the "continuously refactor" approach - that's my ideal. For older legacy stuff, I'm just going to have to keep trying to talk myself into refactoring more, and making sure I have supporting tests.

Don't get me wrong, not all my code is horrid, bad and smelly! It's just that whenever I do make a mess, I very rarely get away with it ;-)

Re: Does It Work?

I'm experiencing this right now on my project. But I wasn't the one who created the code originally. So now I'm having to clean up someone else's mess, and I'm not always sure I'm comprehending what was intended. I vote for cleaning up as you cause a mess, which is the intent of refactoring.

I only refactor code that is working.

If it is not working, then I need to rewrite it.

Re: Does It Work?

Maybe if refactoring with a tool was more intuitive (and we had confidence that it would work!), ugly code wouldn't stay in a system so long? Dynamic Aspects has some demonstrations of a new kinda refactoring tool.

Add a comment Send a TrackBack