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

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 ...
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 ...
5
votes
5answers
199 views

Is there a name for the concept of a hierarchy of many short methods in a class

A refactoring I commonly do is where I come across a large method such as public void doSomething() { // do First thing doPartA1(); doPartA2(); //now something else ...
5
votes
2answers
407 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 ...
5
votes
2answers
227 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
305 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 ...
5
votes
4answers
170 views

What are some common algorithm optimization opportunities - mathematical or otherwise

What are some common algorithmic optimization opportunities that everyone should be aware of? I have recently be revising/reviewing some code from an application, and noticed that it appeared to be ...
5
votes
3answers
241 views

How to justify framework upgrades

I am looking at how to justify changes to those who control budgets. For example if we have Enterprise Library 4 on some systems and the latest version is 5, is it worth upgrading? How do you justify ...
5
votes
4answers
166 views

Dealing with bilingual(spoken language) code?

So I've got to work with this set of code here for a re-write, and it's written by people who speak both English and French. Here's a snapshot of what I'm talking about (only, about 4000 lines of ...
5
votes
3answers
478 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 ...
5
votes
1answer
165 views

How to design an algorithm-heavy and object-light application

Other than vertices, edges, faces and meshes, my geometry processing project/application has only about half a dozen other entities such as curves on surfaces. However the majority of my code is ...
5
votes
7answers
152 views

Can initial inefficient solutions INSPIRE better ones and thus lead to faster problem solving?

When faced with writing an algorithm to solve a small project/problem is it better to come up with pseudo code that isn't efficient/optimum but solves the problem and then try to use the inefficient ...
5
votes
3answers
193 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 ...
5
votes
2answers
114 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 ...
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 ...
5
votes
3answers
449 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 ...
5
votes
2answers
956 views

Are there any good examples of open source C# projects with a large number of refactorings? [closed]

I'm doing research into software evolution and C#/.NET, specifically on identifying refactorings from changesets, so I'm looking for a suitable (XP-like) project that may serve as a test subject for ...
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 ...
5
votes
2answers
95 views

Simplified Interfaces or Object Abstraction

i've been facing a common situation at work that has happened quite often when handling objects. The situation goes like this: You have to realted classes A and B, class A has an instances of class ...
5
votes
1answer
350 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 ...
5
votes
5answers
877 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 ...
4
votes
3answers
467 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 ...
4
votes
7answers
358 views

Should all development, including refactoring work, be accompanied by a tracking issue?

The debate: Should all development, including refactoring work, be accompanied by a tracking issue? (in our case, Jira) The common ground: Our primary goal is quality. A working product, every ...
4
votes
7answers
277 views

Once and only once - with more lines of code

I have an ugly bit of code - essentially iteration over some data structures where the meat of the action was changing, but the iteration code stayed same. The iteration constituted the bulk of code, ...
4
votes
3answers
467 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 ...
4
votes
4answers
577 views

Role of “Refactoring” in good programming pratices?

I have learned in Agile Development that: Refactoring is the process of clarifying and simplifying the design of existing code, without changing its behavior. I have heard about some GUI ...
4
votes
3answers
491 views

Is there a term for reusing code by retyping it?

I built a prototype ("one to throw away") a while ago, and I'm rebuilding it now as an alpha. My goodness, it's been worth it. I reused some of the prototype code by copy-pasting then modifying it, ...
4
votes
3answers
361 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 ...
4
votes
3answers
225 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 ...
4
votes
2answers
546 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
4answers
247 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 ...
4
votes
3answers
348 views

Refactoring Bittersweet PHP: How can I make this less painful?

I've just been assigned a large project. The client has had multiple developers across different companies working on their (intended to be) large, MySQL driven eCommerce site. The DB schema is ...
4
votes
2answers
141 views

Refactoring a live system that is tightly coupled with improper data models and business logic in the front-end

Scenario This was a project that I once had to maintain. After reading Working Effectively with Legacy Code, I started to think how I would refactor this system in a live environment, if I had to ...
4
votes
4answers
178 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) { ...
4
votes
3answers
209 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, ...
4
votes
7answers
563 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
1answer
635 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 ...
4
votes
3answers
219 views

Small refactorings on a poor codebase?

In the last two years I have worked with a poorly written codebase of nearly 40K lines of code. Over that time I have made many small refactorings to improve it and made some bigger, as time permits. ...
4
votes
5answers
2k views

What deters developers from using automated refactoring tools?

I was having a discussion with my colleagues about using the automated refactoring tools in IDEs (Eclipse, NetBeans, IntelliJ, Xcode, Visual Studio, etc) and was surprised that many of them were ...
4
votes
2answers
1k 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 ...
4
votes
3answers
180 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 ...
4
votes
2answers
174 views

How do you create documentation when there is none? [duplicate]

I have recently inherited a large, legacy system with a complex codebase that has a lack of documentation. I'm the sole internal developer embedded with the core users, taking some responsibility from ...
4
votes
2answers
214 views

How should I refactor switch statements like this (Switching on type) to be more OO?

I'm seeing some code like this in our code base, and want to refactor it: (Typescript psuedocode follows): class EntityManager{ private findEntityForServerObject(entityType:string, ...
4
votes
2answers
274 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 ...
4
votes
3answers
1k views

.Net Best Practices : Common Bugs Introduced By Refactoring, Carelessness, and Newbies

What are the common bugs introduced by refactoring, carelessness, and newbies? I would like to request the experienced programmers here to share their experience and list the bugs they used to ...
4
votes
3answers
703 views

Is it okay to call a model method in my view?

In the interest of keeping my Controller's skinny, I put a headline method in a Model. # My Model class Property def headline "#{name} | #{address}" end end (Then, Property Controller for ...
4
votes
3answers
215 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
3answers
280 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 ...
4
votes
1answer
201 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, ...
4
votes
1answer
345 views

Splitting Logic, Data, Layout and “Hacks”

Sure, we all heard of programming patterns such as MVVM, MVC and such. But that isn't really what I'm looking into as Layout, Data and Logic is already pretty much split up (XML-Layout markup, ...