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

3
votes
3answers
122 views

Can removing unnecessary file from a repo be considered part of refactoring?

We're using Git as our DVCS and we're about to start to do a clean up (never done before in this team) of files that are not necessary (not part of the sources) from our products. This is done in two ...
0
votes
0answers
61 views

On the process of replacing an internal framework by a public one [duplicate]

I am working on several applications which depends on a framework which was developed by a prior engineer in the company. The framework was mainly developed and maintained in the early 2000s, and ...
3
votes
1answer
225 views

Object Calisthenics - reducing to two attributes

I'm refactoring an expense tracker system using Object Calisthenics. I'm able to bring my Class down to five attributes. How do I go forward from here? This is my class right now. public class ...
1
vote
2answers
134 views

Code Duplication in Multi-Module Project

I've about seven modules arranged like so: Service Processing Common Account Email Scheduling I try to make it my policy to restrict code to the module that actually uses it. Code that is shared ...
5
votes
3answers
134 views

Engineering a better solution, coming from existing codebase [duplicate]

The Code I have high-business-value daily-used-by-customer software that is written in PHP and spans approximately 600K lines of code. Customer for a long time needs, wants, and demands new features ...
2
votes
3answers
166 views

When subclassing is it better to “Copy Paste, then Refactor”, or “Refactor, then Implement”

I currently have a class Foo, i've decided I need a second type of Foo where I want to test out a significantly different implementation. It will no doubt share some functionality with Foo so I'll ...
1
vote
2answers
198 views

Query Language for Java Code Analysis

I want to write a refactoring tool for the Java programming language. For this reason I need to do structural queries against the abstract syntax tree. Given this AST how do I get answers to the ...
17
votes
4answers
1k views

How to convince/prove my manager that a rewriting is needed rather than a refactoring [duplicate]

My manager wants me to refactor a gigantic amount of terribly-coupled, macroed, full of private namespace methods, hierarchy-perverted (even 10+ levels of inheritance) code which hasn't been (indeed) ...
1
vote
3answers
103 views

Refactoring - Utility classes behavior under a common interface

I was suggested to put my question here, so I'm doing so ;) I need a common interface which represents some specific behavior: public interface Contract(){ public void methodA(); public void ...
5
votes
5answers
587 views

Martin Fowler's Refactoring book: switch statement is using other object's data, why is that bad ? A deeper explanation is sought for.

In the code sample below the Rental object is using Movie's fields to do a switch statement. Martin says : this is a bad idea but he does not give any deeper explanation as to why ? Of course, you ...
9
votes
5answers
1k views

How do you keep your unit tests working when refactoring?

In another question, it was revealed that one of the pains with TDD is keeping the testing suite in sync with the codebase during and after refactoring. Now, I'm a big fan of refactoring. I'm not ...
1
vote
3answers
202 views

Is it good to create static method at Visual Studio refactoring?

There are various refactoring options in Visual Studio to use at the time of coding. When we extract and create a new method. Then Visual Studio decide whether the new method will be static or ...
0
votes
0answers
107 views

Should I start refactor this messy project even if I know I won't have the time to completely refactor everything? [duplicate]

I have this older project (1st release 2005-ish) I've inherited that a customer asks me to fix or add something to now and then. It's a bit of a mess architecture-wise. Basically it's an ASP.NET ...
0
votes
1answer
159 views

Separating UI from logic in JavaScript modules

I'm refactoring some custom JavaScript modules written to support our mapping functionality. I'm looking to make them much more unit-testable and be able to plug pieces in and out more easily. My ...
1
vote
3answers
88 views

How maintainable are automated refactorings? [closed]

Resharper offered to turn my loop: foreach (JObject obj in arr) { var id = (string)obj["Id"]; var accountId = (double)obj["AccountId"]; var departmentName = (string)obj["DeptName"]; ...
2
votes
2answers
154 views

Replacing static classes with global state to a series of POJOs, beginning to feel like an anti-pattern

I'm trying to refactor some code, and one of the major changes is to remove the (ab)use of static classes to give global state. I've tried to split up some of the 'global state' functionality with ...
5
votes
3answers
1k views

Should I refactor a F class from code climate? [closed]

According to code climate (static quality analysis), a class is F, aka the worst mark you could be granted. I did submit a pull request to rearrange it here Which has been refused because the new ...
-1
votes
1answer
108 views

What is meant by a step-by-step refactoring plan describing implementation of design [closed]

What is meant by a step-by-step refactoring plan describing how to implement a certain design? As little as I know about refactoring it regards improving a (UML) design model and has nothing to ...
0
votes
1answer
129 views

Refactoring this code that produces a reverse-lookup hash from another hash

This code is based on the idea of a Form Object http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/ (see #3 if unfamiliar with the concept). My actual code in ...
6
votes
10answers
1k views

What are the most common ways used to migrate a Delphi application incrementally to .NET?

If you have several million lines of Delphi code and want to incrementally migrate to .NET/C#, what strategy would you use?
12
votes
6answers
3k views

Avoid too complex method - Cyclomatic Complexity

Not sure how to go about this method to reduce Cyclomatic Complexity. Sonar reports 13 whereas 10 is expected. I am sure nothing harm in leaving this method as it is, however, just challenging me how ...
0
votes
1answer
80 views

Should a structure be refactored into smaller structures?

In one of the projects (in C), I have the code that looks like this (the names are obfuscated specially for question to not give out details of the probject): typedef struct Module_s { /* These ...
2
votes
2answers
200 views

How to refactor out static members of basic classes

Currently I am working on C++ project, which can be classified as "legacy" project. A lot of poor written code was committed because of lack of experience and under the pressure of deadlines. When I ...
8
votes
10answers
2k views

How to do a clean refactoring of an If Else Code without leaving any free blocks? [duplicate]

if(condition1) { Statement1A; Statement1B; } else if(condition2) { Statement2; } else if(condition3) { Statement3; } else { Statement1A; Statement1B; } return; I would like to ...
0
votes
4answers
398 views

Usage of magic strings/numbers [closed]

This is somewhat controversial topic, and I guess there is as many opinions as there are programmers. But for the sake of it, I want to know what are the common practices in business (or in your work ...
2
votes
4answers
209 views

Considerations before rewriting a software component from scratch? [duplicate]

A piece of software is a patchwork of old and undocumented efforts. There are no comments, no documentation, and the code is hairy -- it involves Unix shell scripts that check for dummy files and then ...
1
vote
0answers
360 views

Thoughts on refactoring a generic DAO

I have designed a generic DAO in Java and am having confusion about whether to refactor it to different design or not. PS Don't say to use already existing 3rd person framework. I know there are some ...
2
votes
2answers
513 views

Why delete method/field/function refactoring doesn't exist in Eclipse?

An operation in an interface is obsolete so I decided to delete it. It seems that there is no automatic support for such a "refactoring" in Eclipse. For me is a refactoring operation since the ...
1
vote
1answer
46 views

Refactoring from Python to Ruby with a BSD v3 license?

There is a project that is written in python which works great and is under the BSDv3 license. I wanted to use it as a base template for a ruby project instead of starting from scratch. I'd be ...
11
votes
5answers
483 views

Code repetition vs multi responsible method

I try to follow the Single Responsibility Principle (SRP) and also to omit Code Repetitions. However there are often places where there are code repetitions that are nothing more than code blocks of ...
5
votes
1answer
1k views

How do I structure a larger Flask application?

I have a relatively simple web application that is written in Python using the Flask microframework. I've really enjoyed Flask's ease of use, however, as the app has grown larger it has started to ...
0
votes
1answer
120 views

Get entities ids from two similar collections using one method

I've got two lists: List<Integer, ZooEntity> zoos; List<Integer, List<ZooEntity>> groupOfZoos; These operations will return collections of values: Collection<ZooEntity> cz ...
9
votes
2answers
346 views

Is spreading code with refactoring comments a good idea?

I am working on a "spaghetti-code" project, and while I am fixing bugs and implementing new features, I also do some refactoring in order to make the code unit-testable. The code is often so tightly ...
13
votes
5answers
1k views

Using functions as a way to stylize [closed]

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 ...
0
votes
1answer
121 views

unit level testing, agile, and refactoring [duplicate]

I'm working on a very agile development system, a small number of people with my doing the vast majority of progaming myself. I've gotten to the testing phase and find myself writing mostly ...
1
vote
1answer
93 views

Proper library for enums

I'm trying to refactor some code such that the display is separate from the implementation, and I'm not sure where to put the existing enums. My project is currently structured as follows: ...
11
votes
5answers
1k views

How to refactor an OO program into a functional one?

I'm having difficulty finding resources on how to write programs in a functional style. The most advanced topic I could find discussed online was using structural typing to cut down on class ...
9
votes
3answers
346 views

How to refactor when all your development is on branches?

At my company, all of our development (bug fixes and new features) is done on separate branches. When it's complete, we send it off to QA who tests it on that branch, and when they give us the green ...
32
votes
4answers
2k 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, ...
19
votes
3answers
1k views

Difficulties With TDD & Refactoring (Or - Why Is This More Painful Than It Should Be?)

I wanted to teach myself to use the TDD approach and I had a project I had been wanting to work on for a while. It wasn't a large project so I thought it would be a good candidate for TDD. However, I ...
2
votes
2answers
221 views

Refactoring two classes from third-party library that could have extended a base class

I have two Classes, with very similar behaviors, both from a third party library. Both needs to be populated with some value object and sent to specific queues in order for logging. Please note both ...
2
votes
3answers
149 views

Should I combine similar functions even though they are slightly different?

On an application I've been working on I have a function, connecting to a virtual machine, that can be performed two ways. The user can either select a machine from a list and click the "Connect" ...
16
votes
7answers
1k views

To rewrite or slowly refactor old C++ project [duplicate]

Our team has recently inherited a relatively large project from another company (~250k lines). It was developed using C++Builder and we intend to port the Ui side to Qt. Most of the Ui code is ...
0
votes
2answers
364 views

Refactorable God v.s. too many classe [duplicate]

So I have this problem: in order to structure my code hierarchically, for every new tiny thing, I create a separate sub-folder, file, class ... and in it one 10-line function. It is an anti-pattern. ...
57
votes
11answers
6k views

Is it a bad practice to modify code strictly for testing purposes

I have a debate with a programmer colleague about whether it is a good or bad practice to modify a working piece of code only to make it testable (via unit tests for example). My opinion is that it ...
1
vote
4answers
202 views

Until what point should I refactor? [duplicate]

What do you think until what point should a programmer refactor the code? Basically having def method do_something end Pieces of code would be handy, but they increase spaghetti code until the ...
9
votes
7answers
986 views

Temporary variables vs line length requirements

I've been reading Martin Fowler's Refactoring. It is generally excellent but one of Fowler's recommendations seems to be causing a little trouble. Fowler recommends that you replace temporary ...
10
votes
7answers
2k views

Best way to break down overwhelming code into manageable chunks?

I'm continually becoming overwhelmed by large projects, once they reach a certain level of complexity. Once I reach a certain point in a project, my progress slows to a crawl and I find myself ...
2
votes
1answer
163 views

Why does the tool offer to change the code - just because it can?

Resharper (or is it Visual Studio - it's a yellow light bulb with a tiny red filament in it) offers to "invert if" on this code: if (tItems >= 0) { return tItems; } SetTotalItemsAndTotalAmt(); ...
-1
votes
1answer
338 views

Is there a tool that visually represents all the potential paths to a particular piece of code? [closed]

As an example of what I need and why I want it, I am trying to determine how a certain value (CurTotal) is getting set (wrongly). I've come up with these notes to myself to try to understand just what ...