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
2answers
149 views

How do I tell my boss that their custom cms is terribly inefficient? [closed]

I started a new job about 2 months ago now with the job title of 'Programmer'. The web dev company I work for had made their own custom CMS and use it for all their sites. Conceptually, the idea is ...
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 ...
3
votes
3answers
393 views

Choosing a random integer in a range such that it doesn't equal a particular number

Given an integer range and a number within that range, what's a reasonably robust and efficient way to randomly select a new number within the range such that it's not equal to the given number? ...
10
votes
6answers
1k views

How do you keep your unit tests working when refactoring?

In another question, it was revealed that one of the pains with TDD is keeping the testing suite in sync with the codebase during and after refactoring. Now, I'm a big fan of refactoring. I'm not ...
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 ...
9
votes
5answers
958 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": ...
1
vote
1answer
101 views

Help Improve DB model/strategy, for use in refactoring SQL-ridden legacy code

Question: Which design pattern do I use to help me refactor legacy SQL code into separate classes? Goal Bring in concepts of data separation and database separation and also latest modern ...
1
vote
1answer
419 views

JSP Include: one large bean or bean for each include

I want to refactor a webapp that consists of very distorted JSPs and servlets. Because we can't switch to a web framework easily we have to keep JSPs and Servlets, and now we are in doubt how to ...
2
votes
1answer
215 views

Convert procedural code to object oriented

I have a PHP application (a web service). It consists of files grouped in directories by theme like :      /customer         /search.php with this example content : Auth::authenticate($options); ...
1
vote
0answers
58 views

Need to refactor file downloader and post processing utility [duplicate]

Not sure whether this is the right forum to ask this but here goes. Using this solution - http://stackoverflow.com/questions/26571351/replacing-if-else-logic-with-state-strategy-pattern I was able to ...
2
votes
3answers
165 views

Refactoring web pages with user controls

Is it good design to use many user controls to help refactor a web application? In my case, it's a VB.NET Webforms ASP.NET website. All our pages are organized into sections that, while related and ...
0
votes
0answers
57 views

API for accessing CTS and DSR signals of serial port

I'm trying to improve another abstraction of the serial port. The project involved often needs to check one of the single control signals CTS and DSR. This is currently done by a call to ...
0
votes
2answers
121 views

Should I worry about performance, even if there is no loss of convenience? [duplicate]

Assume an application that shows a data table. The data is loaded from a database when the program is initialized. Each value in the table is represented by an input field, where each keypress in one ...
2
votes
4answers
168 views

What can be done when you are the only person to care about consistency? [closed]

After reading this question I may have a partial answer to the issue at hand, but I'd like to explore the issue further. I seem to be the only person on my team (a team of 6 people working on an ...
7
votes
6answers
341 views

How best to handle database refactoring within a team?

We are currently usign a roll-forward approach to DB changes, akin to Migrations, where each developer creates and checks in a script that promotes the latest version of the DB to a new state. ...
1
vote
2answers
140 views

Microchip XC8: How to pack code against an upper limit?

I have a project for a PIC16F1454 that needs some custom linking. Basically, I've separated my code into two parts that can be downloaded separately in the field and thus update (almost) all of the ...
2
votes
1answer
123 views

RefactorException: Good idea or bad idea?

When I'm doing large scale refactors I'm often commenting out the contents of methods and using NotImplementedExceptions for stuff that I still need to refactor. Problem is that this is interfering ...
17
votes
6answers
552 views

Is randomly refactoring code allowed in scrum

Background My team uses scrum I have currently no task assigned There are no more pending task in the backlog Today is Labor Day for my client. Not having many things to do today I wanted to start ...
0
votes
2answers
150 views

Designing Nested List<Class> Property in a Class

I'm currently in the class modeling phase of my project. Real life Scenario: Let's say I have a Project that is composed of Main Components and each Main Component is composed of Sub Components and ...
0
votes
3answers
429 views

Eliminate duplicate code in nested IFs without creating a function [duplicate]

Let's say we have two ifs that depend on each other: if var exists { if var is array { //Do stuff with var } else { //Resolve the problem } } else { //Resolve the ...
3
votes
3answers
220 views

How would you rewrite/refactor this ? [duplicate]

Old application that is used by 50-60.000 paying customers. Company is several hundred people big. Application has a lot of business critical code (30% of all code) written in classic asp. Application ...
19
votes
12answers
573 views

Refactor or Concentrate on Completing App

Would you refactor your app as you go or focus on completing app first? Refactoring will mean progress of app app will slow down. Completing app will mean you get a possibly very hard to maintain app ...
2
votes
4answers
217 views

How to refactor a myriad of similar classes

I'm faced with similar classes A1, A2, ..., A100. Believe it or not but yeah, there are roughly hundred classes that almost look the same. None of these classes are unit tested (of course ;-) ). Each ...
0
votes
1answer
124 views

Refactoring a Single Rails Model with large methods & long join queries trying to do everything

I have a working Ruby on Rails Model that I suspect is inefficient, hard to maintain, and full of unnecessary SQL join queries. I want to optimize and refactor this Model (Quiz.rb) to comply with ...
35
votes
7answers
5k views

Why do people nowadays use factory classes so often? [closed]

I've seen the history of several С#/Java class library projects on GitHub and CodePlex, and it seems like a trend. Why do people nowadays use factory classes so often for almost everything? I.e. We ...
0
votes
2answers
259 views

How often do you refactor or restructure your code in long term projects? [duplicate]

As developers we are always eager to learn new things and better ourselves at what we do. You've all had moments when you look at your old code and get that feeling: "WTH, I can't believe I used ...
26
votes
9answers
2k views

Why are deadlines always so short? [duplicate]

I'm a junior developer in a small company (in a team of 2 developers). Everytime we are asked to implement a new feature: the deadline is set so that we just have time to do the development: there ...
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"); ...
0
votes
5answers
493 views

Fixing bugs in other peoples code [duplicate]

I'm working with another programmer and we are always having issues with refactoring or changing each others code. Recently I had to fix a bug, but I pushed the changes before notifying him. He was ...
1
vote
1answer
240 views

I made improvements to free code I found online and notified the author. Was this the right thing to do? [closed]

I recently used a library from http://www.braemoor.co.uk/software/index.shtml (the EU VAT No validation library at http://www.braemoor.co.uk/software/vat.shtml) in a project at work. It mentions as ...
2
votes
3answers
357 views

How can I refactor client side functionality to create a product line-like generic design?

Assume the following situation similar to that of Stack Overflow: I have a system with a front-end that can perform various manipulations on the data (by sending messages to REST back-end): Posting ...
1
vote
3answers
122 views

Can I refactor “safely” without specs? [duplicate]

I have inherited a legacy web application many years which: Does not make use of Object Oriented principles, even though the language would permit it Has no unit tests, nor any sort of test suite, ...
23
votes
10answers
2k views

Eliminating Magic Numbers: When is it time to say “No”?

We're all aware that magic numbers (hard-coded values) can wreak havoc in your program, especially when it's time to modify a section of code that has no comments, but where do you draw the line? ...
8
votes
4answers
881 views

Do I need to upgrade log4j to slf4j [closed]

We are reviewing our JEE web application for some planned refactoring and one of the suggestions is to replace log4j with logback or slf4j The team is not clear on whether we should do this - because ...
4
votes
3answers
580 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 ...
7
votes
1answer
239 views

Suggested method for extracting a standalone C library from an existing R package?

My group has been developing an R package to simulate plant growth (see GitHub repository). The R package uses .Call to interface with C. We have decided that it would be worthwhile to create a ...
2
votes
2answers
173 views

When does extracting methods from code stop to make sense? [duplicate]

I am currently studying the refactoring methods defined by Marting Fowler (http://refactoring.com/catalog/). He states a tip for replacing chunks of code by a single method that does that job. So ...
0
votes
0answers
59 views

Rewriting/decoupling important service of the Django website in Erlang

We have application written entirely in Django, which consist of three separate components. Admin, Service for generating invoices + API and UI for users. Problem is, that they are very tightly ...
1
vote
2answers
260 views

Retrying a statement or call in a catch block - code smell or anti-pattern?

I'm wondering how better to perform this operation for a large amount of files. The bit I'd like some thoughts on whether this copy/paste is acceptable enough of a tradeoff. try to write a file if ...
7
votes
6answers
1k 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 ...
41
votes
12answers
3k views

Reconciling the Boy Scout Rule and Opportunistic Refactoring with code reviews

I am a great believer in the Boy Scout Rule: Always check a module in cleaner than when you checked it out." No matter who the original author was, what if we always made some effort, no ...
2
votes
2answers
327 views

Reduce number of if statements through design pattern

I had a loop through object Process, each process instance can be of a different type, derived from Process base class (e.g.: Process1, Process2,...). Each derived type of Process has different ...
70
votes
6answers
5k views

Fixing a spelling mistake in a method name

One of the methods that I commonly use in our codebase is misspelled (and it predated me). This really irritates me not simply because it is mispelled but more importantly it makes me ALWAYS get the ...
53
votes
17answers
2k views

How can I make refactoring a priority for my team?

The codebase I work with daily has no automated tests, inconsistent naming and tons of comments like "Why is this here?", "Not sure if this is needed" or "This method isn't named right" and the code ...
10
votes
3answers
365 views

Continuing to code on large projects

I am a hobbyist programmer, and I've started many medium - sized projects to work on just by myself. These include games, a raytracer, physics simulations etc. By the time these projects get to a ...
1
vote
1answer
250 views

Advice on refactoring PHP Project

I have a small SAS ERP that was written some years ago using PHP. At that time, it didn't use any framework, but the code isn't a mess. Nowadays, the project grows and I’m now working with 3 more ...
62
votes
10answers
4k 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. I break dependencies, move parts of the code to @VisibleForTesting public static methods and to new classes to make ...
5
votes
2answers
250 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, ...
0
votes
2answers
152 views

Follow the deadlines vs Do it right [duplicate]

I have been given a huge task of migrating few functionalities from jQuery to AngularJS. I have been pretty good at Angular by now. But I want to dive deep and create futuristic, sound architecture. ...
13
votes
7answers
2k views

How to refactor code to some common code?

Background I'm working on an ongoing C# project. I'm not a C# programmer, primarily a C++ programmer. So I was assigned basically easy and refactoring tasks. The code is a mess. It's a huge project. ...