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

2
votes
2answers
322 views

Prevent code from getting mess [duplicate]

I am a student and a freelance programmer. These days I am developing a software in VB6 which has recently crossed 100KB of source code. The main problem, I face is, many times I have to refactor my ...
8
votes
3answers
520 views

What would help when refactoring a large method to ensure that I don't break anything?

I'm currently refactoring a part of a large codebase with no unit tests whatsoever. I tried to refactor code the brute way, i.e. by trying to guess what the code is doing and what changes wouldn't ...
0
votes
1answer
99 views

How to 'convert' a Static Access style project to IoC/DI style?

Are there any best approaches for refactoring a programming project that has previously been written with the static reference anti-pattern (the majority of classes refer at some point to a static ...
3
votes
2answers
525 views

How many regression bugs from refactoring is too many.

Recent QA testing has found some regression bugs in our code. My team lead blames recent refactoring efforts for the regressions. My team lead's stance is "refactor, but don't break too many things", ...
2
votes
1answer
138 views

Agile: When to re-factor and when to extend while accruing technical debt? [duplicate]

Consider the following scenario. You currently have a feature set A you wish to extend to include feature set B. In the near feature there's a high possibility that you wish to extend this even ...
59
votes
7answers
4k views

How do I take responsibility for my code when colleague makes unnecessary improvements without notice?

One of my teammates is a jack of all trades in our IT shop and I respect his insight. However, sometimes he reviews my code (he's second in command to our team leader, so that's expected) without a ...
2
votes
3answers
153 views

Evaluating the complete revision of other's software

I'm having some difficulty to evaluate the revision of a software: the software was paid by customer years ago, never used, and now the customer have noticed that it doesn't work as expected. Now ...
5
votes
2answers
398 views

When is it inappropriate to make objects immutable?

I have a class which represents an entity object in our system (for sake of argument, a Customer object) public class Customer() { private int id; private String name; ... // 30+ fields ...
6
votes
4answers
556 views

Hating your own code - for good or bad, how do you deal with it? [closed]

Have you ever had this feeling that your code is bad, the whole project is a mess, and you just want to step off? On your daily job you can explain this feeling away with your coworkers, asshole boss, ...
1
vote
0answers
124 views

Refactoring expansive message architecture

I am currently working with a system that acts like a message bus. A message comes in to the service (WCF Windows Service hosted). The system then uses a service locator pattern to look up which ...
6
votes
3answers
190 views

Should a new class refactored out of an existing one have history pointing back to it's progenitor

If I split one class into two classes should both classes have history in source control tracing back to the original class that contained both; or should the new class be added as a new file without ...
41
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, ...
4
votes
2answers
540 views

How do I handle having so many SQL queries?

I have an MVC3 project that uses SQL Server. I use data from the SQL database all the time and I often find that I'm reusing/duplicating some SQL queries. I thought I'd solve this problem by creating ...
4
votes
3answers
211 views

Using the mouse as a multi-tool creates heavy conditional logic for executing commands, how do I change this?

The feature is in many different types of editing programs where a mouse click may have completely different commands to execute (using the Command Pattern) Currently I have an overarching ...
4
votes
7answers
499 views

Naming guard clauses that throw exceptions

I have a function evaluate() that parses a String for some variables and replaces them with their corresponding value: public String evaluate() { String result = templateText; for ...
4
votes
2answers
945 views

Is it possible to avoid enormously big switch in that case? [duplicate]

I'm writing a simple chess-related code with intention to write it clearly (performance doesn't matter at all). And this method I have doesn't look clean to me at all: public static Piece ...
5
votes
2answers
214 views

How to do unit tests on a method that takes the elapsed time into account?

I'm currently in the middle of refactoring an important method in a legacy-system. There were almost zero test until I've started working on it, and I've added quite a lot to ensure the correct work ...
5
votes
3answers
288 views

How should I go about “overhauling” a large legacy application? [duplicate]

Possible Duplicate: I’ve inherited 200K lines of spaghetti code — what now? For my next project, I've been tasked with "overhauling" a large legacy web application with many parts. It is a ...
4
votes
3answers
343 views

Renaming long named method in C# [closed]

I'm working on a project where exist one method with title string ValidateNewPasswordExpireCurrentPasswordAndCreateNewPassword(...) I'm sure the method name must be changed. But can't found good ...
7
votes
3answers
532 views

Cleaning Up Generated Code: Refactor or Map?

Context: I recently had to deal with a class file generated by XSD.exe. It was 3500 lines long with ridiculously-verbose class / variable names (think ...
3
votes
2answers
448 views

How to remove duplicate exception block code

I have good number of Service and DAO classes which has the same set of 30 line exception code block which gets repeated and it shows up in Code Duplication report. The approach which i can think of ...
3
votes
2answers
233 views

Overcoming circular reference

I am working on an asp.net MVC web application which contains several projects. One is BusinessObjects, which contains business logic / processes. Another is EmailGeneration which is used to send ...
5
votes
8answers
455 views

Refactoring: Two big chunks within a function

I am designing an API which mostly involves refactoring the original code. So Right now I have a method which has two big chunks which are seperated by an If-else condition, which in my opinion is ...
9
votes
7answers
972 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 ...
4
votes
3answers
274 views

How to refactor “nested” view classes to avoid deep method calls?

Lets say I'm displaying a bunch of data (model) using a View class for rendering. However, a lot of the data has sub-data (models) complicated enough to require separate rendering classes. In my ...
1
vote
1answer
249 views

How to avoid huge functions with made up of enums and if-else or switch case when dealing with server response in iOS?

in my application, I have a request type associated with variety of API calls I make to the REST server. when the response from server comes in the same delegate method for web engine's response, I ...
1
vote
1answer
289 views

How To Explain Need to Refactor Code to Non-Developer Boss [duplicate]

Possible Duplicate: How do you explain refactoring to a non-technical person? How to justify code refactoring time? My supervisor is the CTO of the company that I work at, he is the jack ...
7
votes
3answers
434 views

is this javascript property defaulting pattern a code smell?

In some javascript code I'm working on refactoring I've handled cases where I wanted to default an object property to true without having to go through the code-base and add the property to every ...
21
votes
6answers
1k 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 ...
8
votes
2answers
524 views

Refactoring several huge C++ classes / methods. How to start? [duplicate]

Possible Duplicate: I’ve inherited 200K lines of spaghetti code — what now? I'm dealing with legacy code. It contains some BIG classes (line count 8000+) and some BIG methods (line count ...
9
votes
1answer
203 views

Looking for the better way to combine deep architecture refactoring with feature based development

Problem statement: Given: TFS as Source Control Heavy desktop client application with tons of legacy code with bad or almost absent architecture design. Clients constantly requiring new features ...
1
vote
1answer
133 views

Is it justified to use project-wide unique function and variable names to help future refactoring?

Refactoring tools (like ReSharper) often can't be sure whether to rename a given identifier when, for example refactoring a JavaScript function. I guess this is a consequence of JavaScript's dynamic ...
7
votes
4answers
422 views

Would you refactor this and if so, would you charge your client?

I am working on a freelance job at home. The client wants me to write some new functionality for his CMS, but it is taking me a lot of time to figure out what the code is doing, because it is written ...
0
votes
2answers
235 views

Question on refactoring and code design

Suppose, I have a class with a constant static final field. Then I want in certain situations that field to be different. It still can be final, because it should be initialized in constructor. My ...
3
votes
4answers
378 views

Can notes/to-dos in code comments sent to code-reviews result in an effective refactoring process?

I want to start/improve a culture of collective code ownership at my company but at a geographically distributed level... I'd say there is some current collective code-ownership mentality, but only at ...
22
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 ...
5
votes
1answer
328 views

Music Notation Editor - Refactoring view creation logic elsewhere

Let me preface by saying that knowing some elementary music theory and music notation may be helpful in grasping the problem at hand. I'm currently building a Music Notation and Tablature Editor (in ...
2
votes
2answers
578 views

How Visual Studio could help to avoid duplicating code?

I work within a team of developers. Everyone is making their changes without carrying too much if the same thing is already implemented in the codebase. This leads to classes constantly growing and to ...
14
votes
8answers
732 views

Quantifying the value of refactoring in commercial terms [duplicate]

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 ...
3
votes
1answer
187 views

Refactoring obscurely commented code

In refactoring code, I came across code that had comments. Looking closer at the comments, I could see that the code was clearly not doing what the comments said. Without access to the coder nor ...
5
votes
6answers
678 views

Refactoring and Open / Closed principle

I have recently being reading a web site about clean code development (I do not put a link here because it is not in English). One of the principles advertised by this site is the Open Closed ...
8
votes
4answers
360 views

Rapid prototyping and refactoring

Sometimes when I start a small project (like an android app), I don´t know which approach will work out at the end, and I just go for one approach and give it a try. But if I never used this approach ...
4
votes
4answers
171 views

How to implement isValid correctly?

I'm trying to provide a mechanism for validating my object like this: class SomeObject { private $_inputString; private $_errors=array(); public function __construct($inputString) { ...
2
votes
1answer
744 views

Recovering an anemic domain model into a multitier architecture

I have spent the past several days learning about domain driven design and attempting to apply it to a current project. I decomposed the problem domain into the canonical logical components: domain, ...
0
votes
1answer
128 views

Persuading management that refactoring code is a good idea [duplicate]

Possible Duplicate: Best supporting argument for refactoring Has anyone got any tips for persuading management that refactoring code is a good idea ? I was asked something like "After ...
3
votes
1answer
107 views

Naming a class that processes orders

I'm in the midst of refactoring a project. I've recently read Clean Code, and want to heed some of the advice within, with particular interest in Single Responsibility Principle (SRP). Currently, ...
3
votes
3answers
588 views

How to deal with almost the same enums?

I need to define enums in several classes. The majority of fields are the same in all of the enums. But one has one or two more fields, another has fewer fields. Now I wonder what is the best way to ...
0
votes
3answers
370 views

Introduce unit testing when codebase is already available [duplicate]

Possible Duplicate: Best practices for retrofitting legacy code with automated tests I've been working on a project in Flex for three years now without unit testing. The simple reason for ...
3
votes
1answer
495 views

Replacing out parameters with struct

I'm encountering a lot of methods in my project that have a bunch of out parameters embedded in them and its making it cumbersome to call the methods as I have to start declaring the variables before ...
4
votes
2answers
265 views

What is the right way to group this project into classes?

I originally asked this on SO, where it was closed and recommended that I ask it here instead. I'm trying to figure out how to group all the functions necessary for my project into classes. The goal ...