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

1
vote
4answers
338 views

DRY code, DRY tests?

At some point I had to create some class "Class1" and that class needs a method "method". So I have the following: Class1MethodTest: A total of N tests that check the behavior of Class1.method Class1 ...
2
votes
2answers
107 views

According to software engineering which method are too long? [closed]

I was just working with a method of about 70 lines of code developed by others. It uses a very nice pattern structure, stuff like IOC container, but I wonder.. The method is too long? Is it a so long ...
0
votes
7answers
678 views

Is there any performance benefit in checking the item count prior to executing a foreach loop?

I saw this in code and was wondering if there is any performance benefit to checking the item count prior to looping: if (SqlParams.Count > 0) foreach (var prm in SqlParams) ...
2
votes
4answers
180 views

Should refactoring be the exception or the rule? [closed]

I had a discussion with a co-worker yesterday about design philosophy. The other coder is more experienced then me, and I fully admit that he is likely much better at properly automating his testing, ...
2
votes
2answers
361 views

What is “the refactoring method” for understanding code wrote by someone else?

I wrote code, but I myself many times don't even understand the code i wrote. I heard people using "refactoring method" to help them to understand others' code. I just knew a very little about ...
4
votes
4answers
212 views

How to avoid excessive method overloading?

We have quite a lot of places in the source code of our application , where one class has many methods with same names and different parameters. Those methods always have all the parameters of a ...
0
votes
1answer
60 views

testing: which code layers should I aim to test?

Say I have this code: Design { public function load() { $this->loadProduct(); $this->loadService(); ... } public function loadProduct() { ...
4
votes
3answers
187 views

How to avoid programmers duplicating code [duplicate]

While I know in a perfect world where a greenfield application was scoped out from day one with great BRD's and a competent development lead constantly reviewed code by their underlings to avoid this, ...
0
votes
1answer
139 views

Is there a Pattern or a Refactoring Method to pull data-loading out of existing Class

I am refactoring legacy codebase. Part of it is a loadProduct() function inside a larger "everything" class. loadProduct() loads data from a database. I want to move this loading-data part out of ...
0
votes
0answers
33 views

Best practices for introducing testing to a large, stable, legacy Java application? [duplicate]

I'm working with a stable, but large legacy java application that is over 12 years old, maybe older. Although the code has been upgraded to java 6, it's lacks the features above java 1.4 for the most ...
8
votes
5answers
647 views

Why write tests for code that I will refactor?

I am refactoring a huge legacy code class. Refactoring (I presume) advocates this: write tests for the legacy class refactor the heck out of the class Problem: once I refactor the class, my ...
0
votes
1answer
42 views

Inverse of Extract Interface refactoring

I'm working with a Java project that has several interfaces, many of which have only one implementation. (See related question) For a given revision of the software, one could think this acceptable ...
1
vote
3answers
138 views

How do I evaluate if an Orchestration is the appropriate design pattern for a given problem?

Say that you're doing a code review, and you find yourself faced with an orchestration pattern: class OrchestrationClass { private Configuration _configuration; private DataStore1 _dataStore1; ...
4
votes
2answers
108 views

How to keep track of links pointing to existing web applications in an Intranet?

At my new place of employment we have a Intranet solution containing multiple web applications hosted in IIS. Outside of the development department other departments either source or create other ...
14
votes
7answers
1k views

Should I refactor large functions that mostly consist of one regex? [closed]

I just wrote a function that spans approximately 100 lines. Hearing that, you are probably tempted to tell me about single responsibilities and urge me to refactor. This is my gut instinct as well, ...
3
votes
2answers
115 views

How to handle not-quite-legacy code? [duplicate]

This is a frequently asked topic... And I have read through many posts, articles and am about to read the book Working Effectively with Legacy Code, but before that and mainly because it will take ...
0
votes
1answer
75 views

Am I doing it wrong with Hibernate DAO layer? i.e. Feature Bloat

For quick prototyping I have been actively using Hibernate. Recently I came back to an old project and I wondered why I had a lot of DAOs with what I suspect is commonly named feature bloat. E.g. I ...
1
vote
0answers
59 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
188 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
117 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
118 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
163 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 ...
56
votes
9answers
3k views

Does it make sense to write tests for legacy code when there is no time for a complete refactoring?

I usually try to follow the advice of the book Working Effectively with Legacy Code, so I break dependencies, move parts of the code to @VisibleForTesting public static methods and new classes to make ...
1
vote
2answers
137 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
87 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 ...
3
votes
3answers
114 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 ...
5
votes
5answers
507 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 ...
1
vote
3answers
162 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
138 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
86 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
149 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
100 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 ...
1
vote
2answers
224 views

APIs, Versioning and Models

I have my (JSON) API structured like this (which I'm pretty happy with): API Project /_V1 /Controllers V1EntityController.cs // Applies to version 1 only /_V2 /Controllers ...
0
votes
1answer
78 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
188 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 ...
0
votes
4answers
282 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 ...
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 ...
43
votes
5answers
835 views

How far should we rename code and data when end users nomenclatures change?

A long time ago we added a feature where our users could "Accept" an image after it was added to a workflow queue. Turns out, we used the wrong term, and users actually "Approve" the image. Changing ...
2
votes
4answers
191 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
294 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 ...
3
votes
3answers
374 views

Is it Typical for Large Software Companies to Not Document or Refactor Code? [closed]

I have begun working at a large software company and was assigned to a project that is over a million and a half lines of code. It's part of a program suite that is sold to clients (not an in-house ...
1
vote
1answer
45 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 ...
12
votes
7answers
2k 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 ...
11
votes
5answers
471 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 ...
0
votes
1answer
103 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
345 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 ...
0
votes
1answer
116 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 ...