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)

8
votes
1answer
1k views

Refactoring byzantine payment processing code on a limited budget [closed]

I've been working on a large Ruby on Rails application for several years. It was inherited in a poor state but most of the production bugs have been ironed out with time. There are some sections that ...
1
vote
1answer
83 views

Possible design patterns for a service that synchronizes two third party services [closed]

I am currently in the process of refactoring a web service that synchronizes two third party services. The two services do not really interact well with each other, and there is quite a bit of ...
7
votes
5answers
468 views

Refactoring three very similar classes using inheritance?

I'm currently working on refactoring the code-base for one of our services. I'm been going through reviewing everything, and I feel it's a bit scattered, and could probably adhere to OOP principles ...
3
votes
1answer
2k 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, ...
3
votes
3answers
118 views

Which pattern can I use for doing computations involving similar yet different object subtypes?

How do I design code that has two qualities: uses similar but different subtypes of an object uses similar but different types of computation on the above objects Example I am refactoring this ...
3
votes
5answers
1k views

When are enums NOT a code smell?

Dilemma I've been reading a lot of best practice books about object oriented practices, and almost every book I've read had a part where they say that enums are a code smell. I think they've missed ...
32
votes
9answers
3k views

How clean should new code be? [duplicate]

I'm the lead designer in our team, which means I'm responsible for the quality of the code; functionality, maintainability and readability. How clean should I require my team members' code to be if ...
2
votes
2answers
288 views

Can I wrap a collection with a static class and still call it repository pattern?

I couldn't find a single example about repository pattern using something else then a database. My goal is to have a global static repository that stores some objects in memory. I don't want it to ...
0
votes
1answer
356 views

Switch complex WinForms app to WPF MVVM

This question is connected with my older question C# Application GUI design dependent on configuration. I have built quite big WinForms application working in industry for a few years. It ...
6
votes
3answers
278 views

What data type should Gateway return in Repository Pattern to eliminate refactoring when switching persistence mechanisms?

Following this description of the Repository Pattern, we have three main concerns that need their own classes: The "Repository," which takes and returns Domain Models. The "Gateway," which takes ...
5
votes
7answers
537 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 ...
1
vote
2answers
160 views

Refactoring method with nested loops and 6 variables [duplicate]

I have a method which implements a small section of a (complex) algorithm. This algorithm has taken me several weeks to perfect and is by far the fastest method I can find. The method in question has ...
5
votes
2answers
815 views

Should I always return an error code from C functions?

I have the following code in many places in a large application: if (datastruct.data_ok && cur_time > datastruct.start_time && cur_time < datastruct.end_time) { ...
1
vote
3answers
111 views

@Qualifier and Dependency Inversion Principle

I recently discovered SOLID principles and i'm trying to learn how to properly apply them. I have an application that had a huge interface: public interface NotificationService { public void ...
7
votes
4answers
595 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 ...
9
votes
4answers
758 views

Reducing the complexity of a class

I have looked at some answers and searched on Google, but I could not find anything helpful (i.e., that wouldn't have awkward side effects). My problem, in abstract, is that I have an object and need ...
8
votes
5answers
394 views

How to introduce a new pattern into an existing codebase? [duplicate]

In my quest to better my development skills I learn new design patterns. In sample projects or personal projects it's really easy to adapt new patterns into my code. However at work I have a large ...
11
votes
3answers
373 views

How do you safely refactor in a language with dynamic scope?

For those of you who have the good fortune not to work in a language with dynamic scope, let me give you a little refresher on how that works. Imagine a pseudo-language, called "RUBELLA", that behaves ...
1
vote
2answers
194 views

When is documentation, unit testing, QA and refactoring meant to be done in a 2 week agile sprint?

The team I am working on is trying to do agile development with 2 week sprints. I think we must be doing something wrong however, as we have to work like madmen to get the features implemented in the ...
1
vote
1answer
102 views

How do I refactor a loop that does aggregation while doing it's regular job ?

What am I suppose to do I am working on an API, where I get a list of objects from the output of an SQL query using an ORM. Now this API call needs to send following information down to the client. ...
2
votes
2answers
57 views

Refactor presentation logic from model

I've seen this pattern used in a considerable amount of MVC applications. Let's assume we have a User model with the methods: hasSessionExpired displaySessionExpired The first method ...
1
vote
3answers
473 views

C#6: Should I refactor my code using Resharper for the new features? [closed]

C# 6 is here for a while now and brings with it some syntactic sugar that Resharper is kind enough to highlight and recommend that I "migrate to". Should I apply these fixes automatically to the ...
15
votes
7answers
1k views

Should I refactor large functions that mostly consist of one regex? [closed]

I just wrote a function that spans approximately 100 lines. Hearing that, you are probably tempted to tell me about single responsibilities and urge me to refactor. This is my gut instinct as well, ...
2
votes
2answers
101 views

Delivering source code - refactor for clean up? [closed]

I'm in the middle of developing an asp.net webforms application to a customer, i've been using DataAccess and BusinessLogic layers in a folder structure within my application, in which my DataAccess ...
0
votes
1answer
127 views

Collections.sort question

My question maybe related to this question - Encapsulating Internal Data Structure I have a class LCTile.java which contains a Coordinate.java class. Coordinate.java that contains latitude and ...
2
votes
1answer
242 views

Refactoring a god Manager class

I am running in the exact problem Robert Martin mentioned when having a class named Manager, mine has too much (redudant) code. I am writing a system doing computations on many buffers containing ...
2
votes
2answers
155 views

Refactoring wordy conditional tests [duplicate]

My first attempt at this question was too theoretical, so I've rewritten it with actual code. See the edit history if you care. Supposing this logic, "suffering" from the arrow anti-pattern: /** ...
4
votes
2answers
232 views

Simplifying Some Probabilistic If-Then Spaghetti Code

I've got a fairly substantial code base that I'm trying to simplify. One section in particular deals with probabilistically creating objects. It currently uses hundreds of random number generator ...
0
votes
0answers
54 views

Excessive LINQ chaining - Is it considered a code smell, and why? [duplicate]

I am in a current iteration between design and implementation, and ended up with the following "one-liner": IEnumerable<Channel> ActiveChannels = Receiver.AcquisitionInfo ...
4
votes
1answer
119 views

Should I try to separate state from implementation?

Right now I'm working with some code that combines state and operations. It looks something like this (note: doesn't actually deal with Cars/Trucks. I'm abstracting the business logic here, and ...
1
vote
1answer
299 views

C# Refactoring Code OOD and SOLID [closed]

I’m having some questions regarding improvement of code structure and maintainability, especially regarding SOLID. These questions are specifically for this project, so I would be happy if this ...
3
votes
0answers
159 views

Refactoring to avoid circular references

I'm working on an ASP.NET MVC solution that has two projects, WebUI and DAL. WebUI references DAL. DAL has the repository and context, while WebUI contains Authentication and Authorization classes. ...
40
votes
10answers
34k views

How many lines per class is too many in Java? [closed]

In your experience, what is a useful rule of thumb for how many lines of code are too many for one class in Java? To be clear, I know that number of lines is not even close to the real standard to ...
1
vote
2answers
175 views

Could changing the return type from void to string introduce breaking changes?

This SDK have an interface like this: public interface Contract { void update(..); void action(..); void delete(..); } Now, we need to change it to something like this: public ...
1
vote
3answers
176 views

Handling if-statements with a known duration [duplicate]

I wasn't sure exactly what to call these situations, so I'll illustrate it. If I have something like this in a method: if (i <= 5) doSomething(); else doSomethingElse(); but I know ...
2
votes
3answers
752 views

Unknown design pattern

I am currently trying to refactor some code and one of the problems I came across was the constructors had far too many parameters (15 in fact) and was being initialised by another object which had ...
4
votes
2answers
599 views

Refactoring techniques for asp.net webforms application

I'm working on a large application written in asp.net web forms. It was developed under asp.net 1.0, and still uses DataGrid, though portions have been updated. Most of the code resides in either the ...
2
votes
1answer
282 views

How to approach legacy code? Desperate case [duplicate]

I have a methodological question. I am faced with a reasonably large legacy system (Java Enterprise). I am new to its codebase -as everybody in the team- since it's a product we had in outsourcing ...
2
votes
2answers
118 views

Continue building off an ugly code base or start refactoring? [duplicate]

I'm currently interning at a company where I've been tasked with building an application from scratch. I've been working about 8 weeks, with 4 left to go. I've written a lot of code in that time, but ...
1
vote
0answers
77 views

Managing interdependent project reference in solution file

Context for question I am working on a legacy product, that has multiple projects - Class libraries, websites, windows services, web services etc.. I have a single solution file that contains all ...
1
vote
2answers
208 views

Is the use of set / get prefix discouraged for methods if they don't actually mutate / access fields

This could be a quirk of the IDE I am using, Android Studio, or it could be something more nuanced that I don't understand. I have a method setCustomFont that appears as a property in the Structure ...
38
votes
7answers
3k views

How to measure the potential value of refactoring

On an old, large project with technical debt how can you reliably estimate or measure the benefit of refactoring code? For example, say you have some components within a software stack solution ...
4
votes
3answers
190 views

Clean Code: can private methods rely on member variables set by other private methods?

I was asked to create a class that will connect to a remote service via soap. The class has only one public method send(recordName). The class ended like this: private recordName; private recordId; ...
3
votes
1answer
132 views

PHP Refactoring advice

I'm working on a Soccer management game. Project is fairly new and small and I'm new to PHP. The project was starting to get a bit messy so I've been looking into refactoring. The first thing I've ...
12
votes
7answers
787 views

Developers inheriting code. What to ask the old developer to better help the new developer? [duplicate]

We've had our old iOS developer drop out and we're looking for a new developer or a team to pick up where he has left off. I'm aware there can be issues with developers inheriting code etc. What are ...
2
votes
4answers
683 views

outsourcing code review/refactoring [closed]

I have a small project (3000 lines in Python) that I wrote myself; it has no known bugs and has some decent parts, but is largely a mess because of my lack of time. Unfortunately, I have to be the one ...
0
votes
1answer
60 views

Design review for refactoring a large function

Basic terminology: Report - single report to generate ReportGroup - group of Report(s) to generate Request - contains one or more ReportGroup I'm working on refactoring of the large function (~350 ...
0
votes
1answer
140 views

Passing same argument to multiple small functions versus doing everything in one big function?

I have inherited a class method from another developer, which looks like below: (Note: Class:X means X is a member of Class in the OOP paradigm.) Class:BigFunction() { ImportantValue = ...
1
vote
2answers
90 views

What is the better way of getting different outputs for two very simmilar related workflows

I have a very concrete scenario but I think it would be quite frequent. I'm trying to come up with a solution that it's "better" by better meaning more scalable, reusable and not smelly. I'm working ...
0
votes
2answers
112 views

Refactoring case-when statement [duplicate]

The Product model which can have 2 price tables. The method price calculates the price of the product based on product's price table which is defined by price_table field. class Product < ...