Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.

learn more… | top users | synonyms

92
votes
16answers
4k views

Should I remove unreferenced code?

I'm working on a medium sized (100k lines) code base, it's all relatively recent code (less than a year old) and has good unit test coverage. I keep coming across methods which are either no longer ...
76
votes
8answers
3k views

What is the most effective way to add functionality to unfamiliar, structurally unsound code?

This is probably something everyone has to face during the development sooner or later. You have an existing code written by someone else, and you have to extend it to work under new requirements. ...
66
votes
19answers
4k views

Is it ok to replace optimized code with readable code?

Sometimes you run into a situation where you have to extend/improve some existing code. You see that the old code is very lean, but it's also difficult to extend, and takes time to read. Is it a good ...
52
votes
16answers
2k views

How can I make refactoring a priority for my team?

The codebase I work with daily has no automated tests, inconsistent naming and tons of comments like "Why is this here?", "Not sure if this is needed" or "This method isn't named right" and the code ...
43
votes
16answers
2k views

How do I handle refactoring that takes longer than one sprint?

I work with a code base that is over 500K lines of code. It is in serious need of refactoring. There have been refactoring efforts identified that will take longer than the normal two week sprint. ...
42
votes
6answers
2k views

Refactoring into lots of methods - is this considered clean or not?

So, I watched as my colleague complained a bit about a project he has inherited from someone who is, shall we say, not very experienced as a programmer (intern left to his own devices on a project). ...
42
votes
12answers
2k views

Coding style (do more, then simplify) [duplicate]

I'm a CS student and I have been coding for a few months shy of a year now, and I seem to have developed what I think may be a "bad" habit and I'm wondering if anyone does the same (or whether it's a ...
40
votes
21answers
5k views

How do you explain refactoring to a non-technical person?

(This question was inspired by the most-voted answer here) How do you go about explaining refactoring (and technical debt) to a non-technical person (typically a PHB or customer)? ("What, it's going ...
40
votes
10answers
2k views

Is it a good idea to schedule regular time to clean up code? [closed]

I'm managing a small team of developers. Every so often we decide we're going to spend a day or two to clean up our code. Would it be a good idea to schedule regular time, say 1 week every 2 months, ...
35
votes
11answers
1k views

How do people doing TDD handle loss of work when doing major refactoring

For a while I have been trying to learn to write unit tests for my code. Initially I started out doing true TDD, where I wouldn't write any code until I'd written a failing test first. However, I ...
35
votes
10answers
2k views

How can one best avoid writing bloated GUI code?

I find whenever I work with GUI code, the code tends to bloat faster then other kinds of code. It also seems harder to refactor. Whereas in other kinds of code I can refactor pretty easily -- I find I ...
32
votes
4answers
1k views

What is the term for this type of refactoring

I am sure there is a term for the following bit of refactoring, but I can't remember it and my Google-fu is failing me! The refactor moves if statements to where they are going to have most impact, ...
30
votes
17answers
1k views

Is it bad to have an “Obsessive Refactoring Disorder”?

I was reading this question and realized that could almost be me. I am fairly OCD about refactoring someone else's code when I see that I can improve it. For example, if the code contains duplicate ...
29
votes
7answers
999 views

Code maintenance: keeping a bad pattern when extending new code for being consistent, or not?

I have to extend an existing module of a project. I don't like the way it has been done (lots of anti-pattern involved, like copy/pasted code). I don't want to perform a complete refactor for many ...
28
votes
12answers
2k views

How to handle coworker with “obsessive refactoring disorder”

My coworker (who is very clever, but with severly limited inter-personal skills), keeps refactoring my code even when it is work in progress and assigned to me as a task. Whereas I fully subscribed to ...
27
votes
9answers
2k views

How clean should new code be? [duplicate]

I'm the lead designer in our team, which means I'm responsible for the quality of the code; functionality, maintainability and readability. How clean should I require my team members' code to be if ...
26
votes
11answers
908 views

Techniques to re-factor garbage and maintain sanity?

So I'm sitting down to a nice bowl of c# spaghetti, and need to add something or remove something... but I have challenges everywhere from functions passing arguments that doesn't make sense, someone ...
26
votes
13answers
960 views

How far can I push refactoring without changing external behavior?

According to Martin Fowler, code refactoring is (emphasis mine): Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing ...
24
votes
12answers
2k views

What is best practice on ordering parameters in a function?

Sometimes (rarely), it seems that creating a function that takes a decent amount of parameters is the best route. However, when I do, I feel like I'm often choosing the ordering of the parameters at ...
23
votes
6answers
643 views

What payoffs have you seen from taking care of technical debt?

This article on technical debt has some good points, including: Working on the "technical matters" works best when it is driven by stories. The code base is probably in need of work everywhere, ...
22
votes
15answers
846 views

How do I convince my team to use smaller classes/methods?

Disclaimer: I'm a newcomer (this is my third day of work), and most of my teammates are more experienced than me. When I look at our code, I see some code smells and bad engineering practices, like ...
22
votes
12answers
1k views

Colleague unwilling to use unit tests “as it's more to code”

A colleague is unwilling to use unit tests and instead opting for a quick test, pass it to the users, and if all is well it is published live. Needless to say some bugs do get through. I mentioned ...
21
votes
5answers
1k views

What is the politically correct way of refactoring other's code?

I'm currently working in a geographically distributed team in a big company. Everybody is just focused on today's tasks and getting things done, however this means sometimes things have to be done the ...
19
votes
13answers
1k views

When is it acceptable to NOT fix broken windows?

In reference to broken windows, are there times when refactoring is best left for a future activity? For example, if a project to add some new features to an existing internal system is assigned to a ...
18
votes
4answers
809 views

How to drastically improve code coverage?

I'm tasked with getting a legacy application under unit test. First some background about the application: It's a 600k LOC Java RCP code base with these major problems massive code duplication no ...
17
votes
15answers
1k views

Refactoring: Isn't it just a fancy word for clean up your code?

Before Martin Fowler's book "Refactoring: Improving the Design of Existing Code" came out, we used to call major changes to code "rearchitecture" and minor changes "cleanup". IMO, refactoring ...
17
votes
9answers
1k views

Eliminating Magic Numbers: When is it time to say “No”?

We're all aware that magic numbers (hard-coded values) can wreak havoc in your program, especially when it's time to modify a section of code that has no comments, but where do you draw the line? ...
17
votes
7answers
7k views

How many lines per class is too many in Java?

In your experience, what is a useful rule of thumb for how many lines of code are too many for one class in Java? To be clear, I know that number of lines is not even close to the real standard to ...
17
votes
8answers
575 views

Dealing with coworkers when developing, need advice [closed]

I developed our current project architecture and started developing it on my own (reaching something like, revision 40). We're developing a simple subway routing framework and my design seemed to be ...
17
votes
8answers
539 views

Does anyone else have a refactoring problem?

It seems like after I've written a significant amount of code I get this anxious feeling like I haven't done it in the best possible way, and I end up continuously refactoring and spending way too ...
16
votes
7answers
890 views

If a fluent coder disregards good practices, doesn't his fluency work against him?

I am working on a fairly large and buggy application - and due to the way it's written (I'll spare you details, but it violates rules in most areas you can think of), it is next to impossible ...
16
votes
11answers
407 views

Refactor or Concentrate on Completing App

Would you refactor your app as you go or focus on completing app 1st. Refactoring will mean progress of app app will slow down. Completing app will mean you get a possibly very hard to maintain app ...
16
votes
12answers
784 views

Is it ok to write a quick software programme and then refactor it?

In my team, people have tendency to develop a POC (which is very close to actual deliverable in terms of features) which takes good amount of time to be created. And then spend a significant time to ...
16
votes
7answers
583 views

What can you do about the quality of existing integration and unit tests while being the new guy in a team ?

A recurring theme that I came across in my career is being the new developer to arrive in a team, and quickly having an inherent distrust of the existing unit and integration test suites. During the ...
16
votes
5answers
984 views

How do I prevent unknowningly duplicating code?

I work on a rather large code base. Hundreds of classes, tons of different files, lots of functionality, takes more than 15 minutes to pull down a fresh copy, etc. A big problem with such a large ...
15
votes
5answers
2k views

What are the key points of Working Effectively with Legacy Code?

I've seen the book Working Effectively with Legacy Code recommended a few times. What are the key points of this book? Is there much more to dealing with legacy code than adding unit/integration ...
15
votes
10answers
603 views

suggesting large changes/a rewrite as an intern

The context: it's an internal project (that I don't think a lot of people use) it's old we're updating it The issues: it abuses the mvc framework (no use of models, business logic in views, etc) ...
15
votes
6answers
654 views

How can I refactor a code base while others rapidly commit to it?

I'm on a private project that eventually will become open source. We have a few team members, talented enough with the technologies to build apps, but not dedicated developers who can write ...
15
votes
8answers
825 views

When to refactor

I've read through most of Fowler's Refactoring book and have refactored many applications in my past big and small. One of the harder things I find to teach is "when" to refactor. I tend to do this ...
14
votes
18answers
1k views

Why write clean, refactored code?

This is a question I've been asking myself for a long time. Thought of throwing out it to you. From my experience of working on several Java based projects, I've seen tons of codes which we call ...
14
votes
9answers
946 views

We're not a software company. Is a complete re-write still a bad idea?

I understand the reasoning behind Joel Spolsky's article "Things You Should Never Do, Part I", but I always see it referenced in regards in situations where the end goal is the production of software. ...
14
votes
10answers
806 views

How to fix the copy/paste-pattern?

Where i work, people (consultants) feel pressed to release features as fast as possible. So instead of spending too much time on thinking about how to do things the right way or because they don't ...
14
votes
8answers
569 views

Quantifying the value of refactoring in commercial terms

Here is the classic scenario; Dev team build a prototype. Business mgmt like it and put it into production. Dev team now have to continue to deliver new features whilst at the same time pay the ...
14
votes
11answers
372 views

Should you fix preexisting defects while working on something else?

Conundrum: During the course of working on a new feature or fixing a defect, you find a legacy problem in code. What should you do? Fix it and risk altering the behavior of the code. It has either ...
14
votes
6answers
523 views

How to determine the priority and severity of a “code improvement”?

We have "priority" and "severity" fields in our bug tracking system. We define severity as "how it impacts the user" and priority as "how it impacts the product". My question is about how to ...
13
votes
7answers
729 views

Using functions as a way to stylize

Have you ever broken up a large function into smaller functions knowing that those smaller functions will not be called by more than one caller? The primary purpose of a function is to promote code ...
13
votes
7answers
657 views

How to justify code refactoring time?

Have a very large project more than 70k LOC. The project definitely needs some code refactoring in Core Framework and in other parts as well. There was NO time set in the beginning of the project for ...
13
votes
7answers
785 views

Should I change author name in class file if I make more than 80% changes?

I am refactoring existing set of java test classes for automated UI tests. At times I end up in making massive changes in class file or completely revamping it. This makes me think that when I am ...
13
votes
3answers
294 views

Low impact refactoring and code cleaning of sloppy code while waiting for requirements

I inherited an existing code base for a product that is reprehensibly sloppy. The fundamental design is woefully inadequate which unfortunately I can do little about without a complete refactor (HIGH ...
12
votes
5answers
1k views

Why is my class worse than the hierarchy of classes in the book (beginner OOP)?

I am reading PHP Objects, Patterns, and Practice. The author is trying to model a lesson in a college. The goal is to output the lesson type (lecture or seminar), and the charges for the lesson ...

1 2 3 4 5