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
1answer
1k 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
138 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
121 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
966 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 ...
1
vote
3answers
468 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
640 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
305 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 ...
0
votes
2answers
410 views

Breaking up a large PHP object used to abstract the database. Best practices?

Two years ago it was thought a single object with functions such as $database->get_user_from_id($ID) would be a good idea. The functions return objects (not arrays), and the front-end code never ...
7
votes
6answers
2k views

What to do when you inherit an unmaintainable codebase? [duplicate]

Possible Duplicate: Techniques to re-factor garbage and maintain sanity? I've inherited 200K lines of spaghetti code — what now? I'm currently working at a company with 2 other ...
6
votes
3answers
3k views

How do I break down and plan a personal programming project? [closed]

I've just started a programming job where I'm applying my 'How to code' knowledge to what I'm being taught of 'How to Program' (They are different!). As part of this, I've been taught how to capture ...
6
votes
7answers
432 views

Is there such thing like a “refactoring/maintainability group” role in software companies?

So, I work in a company that does embedded software development, other groups focus in the core development of different products' software and my department (which is in another geographical ...
6
votes
3answers
170 views

What do I need to learn to decide on rename/recompile source package names because of company rebranding?

My company is currently at a rebranding process and the brand names have been used in the sources' package names but these names are only visible to developers who maintain this code so nobody from ...
5
votes
3answers
516 views

CTO has left — codebase is a huge kludge, any advice on how to manage/handle/damage control? [closed]

I began work at a company 2 months ago as a PHP developer. I stepped in to somewhat of a kludge, but I've yet to find a company that isn't... The development stable is currently two developers ...
9
votes
5answers
1k views

How to unit test a function that is refactored to strategy pattern?

If I have a function in my code that goes like: class Employee{ public string calculateTax(string name, int salary) { switch (name) { case "Chris": ...
11
votes
3answers
489 views

How do you break out of the role of a code maintainer? [closed]

In my last three jobs, I was a code maintainer. In all three cases, I was hired after the majority of the code for the project was already written. I'm a self taught programmer. Before I ever started ...
4
votes
3answers
235 views

Is an Inner Function Justified in this Situation

I'm new to the functional programming concepts in C#, but I have some experience with higher order functions via Haskell, Scala, Python and Ruby. I'm currently going through an old .NET 2.0 codebase ...
8
votes
4answers
765 views

How to deal with code reuse philosophy?

I constantly find myself thinking about code reuse when starting a new project. To what extent should I make my code reusable? Should I limit it to the application scope or should I make it reusable ...
3
votes
2answers
204 views

How long does one have to wait to consider design change in code?

I had a few days ago. I was having trouble with threads. Had lots of questions asked on StackOverflow and honestly for the first time I did not get the answer I was looking for. Finally, I decided to ...
8
votes
6answers
1k views

What are the practical ways to implement the SRP?

Simply what are the practical techniques people use to check if a class violates the single responsibility principle? I know that a class should have only one reason to change, but that sentence is ...
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, ...
7
votes
4answers
184 views

Controllers and re-factoring for maintainability / sensibility

I have read many posts similar to this on the site: however I still am questioning what is best in my situation (also the answers are contradicting from question to question). I have a website ...
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
126 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
575 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
512 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
858 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
826 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
7k 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"); ...
73
votes
19answers
6k 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
222 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
567 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
847 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
484 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
220 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 ...
17
votes
6answers
6k 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
197 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
1k 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
118 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
186 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
491 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
193 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
366 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 ...