Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Premature refactoring? [closed]

We have all heard of premature optimization, but what do you think about premature refactoring? Is there any such thing in your opinion? Here is what I am getting at.

First off, reading Martin Fowler's seminal work "Refactoring" quite literally changed my life in regards to programming.

One thing that I have noticed, however, is that if I start refactoring a class or framework too quickly, I sometimes find myself coded into a corner so-to-speak. Now, I suspect that the issue is not really refactoring per se, but maybe premature/poor design decisions/assumptions.

What are your thoughts, insights and/or opinions on this issue? Do you have any advice or common anti-patterns related to this issue?

EDIT:

From reading your answers and reflecting on this issue more, I think I have come to the realization that my problem in this case is really an issue of "premature design" and not necessarily "premature refactoring". I have been guilty of assuming a design and refactoring in that direction to early in the coding process. A little patience on my part to maintain a level of design agnosticism and focus on refactoring towards clean code would keep me from heading down these design rabbit trails.

like image 321
Swim Avatar asked Mar 14 '09 20:03

Swim


People also ask

Is Premature optimization bad?

Premature optimization, at the microscopic level, is usually a bad idea. This does not suggest, however, that engineers should not be concerned about application performance. The fallacy that "premature optimization" is the same thing as "concern about performance" should not guide software development.

How can premature optimization be prevented?

Avoid premature optimization by getting user feedback early and often from your users. If you need help optimizing the performance of your application, be sure to check out our offerings. Prefix can help you find performance problems as you write your code.

Is refactoring the same as Tech debt?

What I mean by that is refactoring typically refers to software or code, while technical debt can surface even in documentation or test cases. So it can be a bit broader if you want to consider it in that context.

What is the three rules of computing?

They're focused on data portability, integrity, and security.


1 Answers

I actually think the opposite.

The earlier you start thinking about whether or not your design needs refactoring, the better. Refactor constantly, so it's never a large issue.

I've also found that the more I refactor early on, the better I've gotten about writing code more cleanly up front. I tend to create fewer large methods, and have fewer problems.

However, if you find yourself "refactoring" yourself into a corner, I'd expect that is more a matter of lack of initial design or lack of planning for the scope of use of a class. Try writing out how you want to use the class or framework before you start writing the code - it may help you avoid that issue. This is also I think one advantage to test driven design - it helps you force yourself to look at using your object before it's written.

Remember, refactoring technically should NEVER lock you into a corner - it's about reworking the internals without changing how a class is used. If your trapping yourself by refactoring, it means your initial design was flawed.

Chances are you'll find that, over time, this issue gets better and better. Your class and framework design will probably end up more flexible.

like image 138
Reed Copsey Avatar answered Oct 26 '22 23:10

Reed Copsey