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

15
votes
7answers
1k 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 ...
0
votes
1answer
123 views

How far should I expose this status enum?

I wrote a little app to manage an arbitrary series of tasks (e.g., call a SQL sproc and capture out-vars, run another app, run an SSIS package) with dependencies between tasks. Each task has a status ...
3
votes
2answers
96 views

Handling fast growing multi-function services

My team has been developing a web business application for more than a year. It started quite small, but now it is growing bigger and bigger. I think it's time for refactoring. Looking at the code, I ...
3
votes
2answers
1k views

Refactor class (extract methods) in a main / helper classes

Simply spoken, one of my c# classes got too big and I'm currently splitting this class in several subclasses by clustering semantically related methods (actually actions, which do side effects). So, ...
5
votes
3answers
528 views

Starting on a large project, should I split it into more concise parts?

Background: Currently an intern at a company and working on repurposing older programs (still in use, but for different departments) for use in testing new hardware. The new hardware is different in ...
8
votes
2answers
507 views

How do you call the process of taking a part of a function and making an individual function of it?

I know there was a technical term for this. I'm just can't remember what it was. If the title needs clarification, here is what I mean; If this is the old code: Result foobar(Param1,Param2,Param3) { ...
3
votes
1answer
114 views

How should I write new code when the old codebase and the environment uses lots of globals in PHP

I'm working in the Wordpress environment which itself heavily relies on globals and the codebase I'm maintaining introduces some more. I want this to change and so I'm trying to think how should I ...
3
votes
1answer
770 views

How to refactor a method which breaks “The law of Demeter” principle?

I often find myself breaking this principle (not intentially, just through bad design). However recently I've seen a bit of code that I'm not sure of the best approach. I have a number of classes. ...
2
votes
7answers
773 views

After how much line of code a function should be break down?

While working on existing code base, I usually come across procedures that contain Abusive use of IF and Switch statements. The procedures consist of overwhelming code, which I think require ...
8
votes
9answers
6k views

Use constructor or setter method?

I am working on a UI code where I have an Action class, something like this - public class MyAction extends Action { public MyAction() { setText("My Action Text"); ...
72
votes
19answers
5k 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 ...
2
votes
4answers
212 views

Good design for class with similar constructors

I was reading this question and thought that good points were made, but most of the solutions involved renaming one of the methods. I am refactoring some poorly written code and I've run into this ...
4
votes
3answers
548 views

How should I start refactoring my mostly-procedural C++ application?

We have a program written in C++ that is mostly procedural, but we do use some C++ containers from the standard library (vector, map, list, etc). We are constantly making changes to this code, so I ...
5
votes
1answer
762 views

How to unit test large legacy systems? [duplicate]

Possible Duplicate: Best practices for retrofitting legacy code with automated tests When working in large legacy systems (large systems with no unit testing ever) I often come across ...
1
vote
2answers
431 views

Setting variable in constructor or within method

I have a class which contains two methods. These methods add & remove an object to a datastore. The class which contains these methods has a no arg constructor but each of the two methods takes ...
0
votes
1answer
203 views

Reorganizing code based on dependencies

I'm wondering if there is a tool that can generate a dependency graph between C language object files and then analyze how to turn that graph into a DAG by modifying code that creates cycles, moving ...
13
votes
7answers
2k views

A defense for boilerplate?

To me, boilerplate code is obviously bad. However I've met a developer who displays resistance in any attempt to reduce boilerplate. I realized I didn't have a readily formed, well thought out ...
15
votes
6answers
5k views

Refactoring Switch Statements and is there any real use for Switch Statements at all?

I was reading this article and was wondering, do we get rid of all switch statements by replacing them with a Dictionary or a Factory so that there are no switch statements at all in my projects. ...
5
votes
3answers
196 views

When is 'cloning', rather than reusing, a module acceptable design solution?

For this question, I'll give an example module to facilitate the discussion, Let's say the module is a calculation engine, It currently servers its purpose for its current audience. The requirement is ...
6
votes
3answers
975 views

Replace Type Code with Class (From Refactoring [Fowler])

This strategy involves replacing the likes of this: public class Politician { public const int Infidelity = 0; public const int Embezzlement = 1; public const int FlipFlopping = 2; ...
0
votes
2answers
116 views

How should I refactor so that responsibility for a geocoding service is shared appropriately?

First, some background. I have an application that requires the use of several external geocoding providers which I don't control. It uses a central service layer inside the application to dispatch to ...
39
votes
10answers
4k 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 ...
21
votes
13answers
2k 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 ...
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 ...
4
votes
3answers
181 views

Is there a resource that explains the benefits of layered programming?

Let's say we have a winform application with a buttonclick event. The buttonclick handles everything from the UI configuration to the database call and data manipulation. So you end up with a method ...
8
votes
7answers
475 views

Refactoring While Programming

When posed with a problem, particularly when it is complicated in nature, I try to take some time to think about the approach I am going to take to solve the problem. Despite this, what often happens ...
3
votes
3answers
181 views

To reorganize code, what to choose between library and service?

I want to reorganize a large application with lot of code duplication into multiple components. Plus, some code is also duplicated over other applications. The common set of functionality that can be ...
9
votes
1answer
1k views

How to refactor a Python “god class”?

Problem I’m working on a Python project whose main class is a bit “God Object”. There are so friggin’ many attributes and methods! I want to refactor the class. So Far… For the first step, I ...
10
votes
4answers
355 views

Handling “related” work within a single agile work item

I'm on a project team of 4 devs, myself included. We've been having a long discussion on how to handle extra work that comes up in the course of a single work item. This extra work is usually things ...
15
votes
6answers
813 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 ...
9
votes
6answers
560 views

Software solution from the 2000's, should I attempt to patch or remake the whole thing?

I was sent out to discuss a system that a certain company is currently using and what should be done with it. The company manufactures various carton displays. This system was developed to keep track ...
0
votes
4answers
711 views

How to deal with bad code? [duplicate]

Possible Duplicate: Techniques to re-factor garbage and maintain sanity? Code maintenance: keeping a bad pattern when extending new code for being consistent, or not? I was hired about ...
9
votes
7answers
967 views

Should I be bothered if my LOC/day ratio is too high?

I'm currently working on an indie project, so I don't exactly have the luxury of throughout human testing or external code review — however, I don't see any difficult bugs in my current code (I fix ...
14
votes
6answers
777 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 ...
2
votes
2answers
82 views

Is it possible to analyse the API surface of a set of class libraries to automatically determine inter-assembly dependencies?

I'm sure we've all been in the situation where we've inherited code that was "overly public", becomes obsolete or needs to be refactored. In these situations, it is easy to spend many days analysing ...
6
votes
3answers
895 views

How to explain your non-programmer boss you need to refactor a whole site?

First of all, is not a programming matter, is a programmer afair. I'm the new web programmer in my company. I'm here just for 2 weeks. And they want me to teach Wordpress, configure & install it, ...
17
votes
9answers
2k 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 ...
81
votes
8answers
5k views

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

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. ...
2
votes
2answers
822 views

Right design pattern to use StopWatch class

I have to measure execution time for a blocks of code. I had implemented simple StopWatch class like http://www.goldb.org/stopwatchjava.html. If I will invoke methods of StopWatch class directly ...
36
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 ...
2
votes
2answers
721 views

What are some good small-scale refactoring tests? [closed]

I'm looking to test potential candidates on their ability to develop concise, reusable code. I feel like a good test of that skill would be to give them a very small scale application or class ...
3
votes
2answers
410 views

Methods to rewrite a program [duplicate]

Possible Duplicates: How to approach refactoring an existing web application? Starting a coherent architecture in a legacy application We have a fidelity system running on the company I ...
6
votes
1answer
418 views

Refactoring an existing MVC codebase to remove business logic & data access from the Controllers

Product I've inherited has the following composition: MVC web site where the controllers make calls to Repositories to get, insert and update objects retrieved that are defined in the: Data ...
11
votes
3answers
800 views

What are good ways to organize input files (Makefiles, SConstruct, CMakeLists.txt, etc.) to build automation software?

One thing I like to do with my code is make sure that it's refactored into manageable pieces. However, when it comes to building the software, I find that whatever build automation software I end up ...
12
votes
5answers
607 views

How does one determine whether or not to rewrite poorly-designed code? [duplicate]

Possible Duplicate: When is a BIG Rewrite the answer? I'm on a small team that's been handed a poorly-written, half-finished 2D Java game. Our objective is to do as much as we can to make ...
3
votes
2answers
350 views

What are the three main technologies for a redesign of a COBOL legacy system

There exists an application that reports financial data of a bank to a national bank (all located in Europe). It is a legacy system that is written mainly in COBOL. Only the user interface is written ...
12
votes
7answers
812 views

After writing code, why do I feel that “I would have written better” after some time? [closed]

I have been working on my hobby project in C++ for more than 2 years. Whenever I write a module/function, I code it with lot of thinking. Now see the problem, do { --> write the code in module ...
4
votes
1answer
206 views

Should I refactor this rails application?

I have taken over the code base for a ruby-on-rails application which relies very heavily on ActiveRecord callbacks to perform domain rules. The application can be compared to a bank application, ...
6
votes
1answer
351 views

General approach to re-factoring an large, very badly written legacy system [duplicate]

Possible Duplicate: Techniques to re-factor garbage and maintain sanity? What is a good way to refactor a large, terribly written code base by myself? Really open question here. I'm not ...
5
votes
5answers
1k views

Example bad code project to motivate refactoring / good design [closed]

This is sort of the opposite of Is there an open-source project that can be an example of well-written code?. I am teaching software engineering to undergraduates and I would like a blob of object ...