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)

1
vote
3answers
147 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
665 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 ...
1
vote
3answers
138 views

Design pattern for different code behaviors according to different clients

At my company, we have a solution composed of a WinForm (multiple per client) and an API (one per client). This solution is deployed on different clients that require the solution to behave ...
4
votes
2answers
515 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
219 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
86 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
42 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
146 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 ...
1
vote
1answer
53 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 ...
36
votes
7answers
2k 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 ...
1
vote
1answer
64 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 ...
4
votes
3answers
119 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; ...
1
vote
2answers
116 views

Alternatives to using dictionary in parameters in C#?

I have a method that takes in a dictionary and enum value and produces a string output. Enum value defines what template string to insert the dictionary key value pairs into. public string ...
3
votes
1answer
98 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
735 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
617 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 ...
1
vote
1answer
421 views

How To Explain Need to Refactor Code to Non-Developer Boss [duplicate]

Possible Duplicate: How do you explain refactoring to a non-technical person? How to justify code refactoring time? My supervisor is the CTO of the company that I work at, he is the jack ...
1
vote
2answers
165 views

Is there a pattern to assist with working around or fixing violations of the Liskov Substitution Principle? [closed]

I've come across a rather large violation of the Liskov Substitution Principle in our codebase. There is an abstract class. Within it is an abstract method, implementers of which are expected to ...
0
votes
1answer
48 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
106 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
85 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
91 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 < ...
36
votes
8answers
2k views

Code maintenance: keeping a bad pattern when extending new code for being consistent, or not?

I have to extend an existing module of a project. I don't like the way it has been done (lots of anti-pattern involved, like copy/pasted code). I don't want to perform a complete refactor for many ...
5
votes
2answers
507 views

Is it possible to refactor inheritance to composition when virtual methods are called inside the base class?

Let's say I have a class called Country and two subclasses called AI and Player. The Country class has a number of virtual methods to allow player-specific or AI-specific behavior. I want to make it ...
0
votes
1answer
76 views

Code Inside Catch Block

This question is related to both of these questions - Efficient try / catch block usage? and Dealing with error in data - Idempotent approach. When I encounter a void while reading a GIS data file I ...
2
votes
2answers
316 views

Refactoring long methods with a lot of cyclomatic complexity

I'm attempting to refactor what is becoming a very large method -- currently 350 or so lines -- that contains a high degree of cyclomatic complexity. I understand and ascribe to the theories that ...
6
votes
3answers
284 views

How to explain design decisions when refactoring code

I am working on a colleague to refactor the following code, I am trying to turn this into a teaching experience as well. Original Code public class WidgetRepository { public Widget ...
29
votes
11answers
3k views

What factors should influence how I determine when to abandon a small project with a friend? [closed]

I've found myself in a tough spot as of late. Been working on a game with a programming buddy for nearly 8 months now. We both started off as newcomers to programming around August of last year, he is ...
2
votes
1answer
216 views

Refactoring code with just a few lines different

I have two for loops in a function which look like these: for (int i=0; i < MAX; ++i) { identical_lines identical_lines identical_lines first_for_specific_line identical_lines ...
38
votes
7answers
8k 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 ...
19
votes
4answers
3k views

How much refactoring is acceptable? [duplicate]

I am currently in a project where one of my developer colleagues constantly refactors stuff on every ticket he's doing. We are using agile methodologies. I know that refactoring is a good thing to do ...
5
votes
2answers
3k views

Refactoring C++ [closed]

I know that there are some other questions about C++ refactoring, but none satisfies my needs. I have a background in Java and Python programming, but now I'm approaching C++. I've read (and ...
18
votes
1answer
879 views

How much time should I dedicate to refactoring my code? [closed]

I don't know if it's just with me, but when I start refactoring some code I waste a lot time doing that and it never ends. Every time I read the code again, I find something that can be improved, ...
4
votes
4answers
937 views

Is it always a good idea to divide large classes into smaller ones? [duplicate]

I've heard time and time again that in object-oriented programming, you should try to split objects that 'do too much' into multiple classes, to avoid the "God Object" problem. This seems like fine ...
83
votes
15answers
8k views

TDD Red-Green-Refactor and if/how to test methods that become private

as far as I understand it, most people seem to agree that private methods should not be tested directly, but rather through whatever public methods call them. I can see their point, but I have some ...
23
votes
11answers
2k views

Does Refactoring towards Looser Coupling, Smaller Functions, and Separate Classes affect System Performance? (and Should I Care)

In Computer Science field, I have noticed a notable shift in thinking when it comes to programming. The advice as it stands now is write smaller, more testable code refactor existing code into ...
1
vote
4answers
2k views

Usage of magic strings/numbers [closed]

This is somewhat controversial topic, and I guess there is as many opinions as there are programmers. But for the sake of it, I want to know what are the common practices in business (or in your work ...
2
votes
2answers
173 views

Unit testing and reusing extracted class

Currently I have 3 service classes, they all have a similar pattern, and I need to make a 4th service class which amalgamates the functionality of the other three. Current three classes public class ...
-1
votes
0answers
45 views

Porting an existing iOS project to cross-mobile technology [on hold]

I am in a refactoring phase of the development of a project. It consists of about 10k-15k LOCS at the moment. It is entirely written in Objective-C for iOS. The problem is the following: in the hurry ...
4
votes
4answers
182 views

Design question concerning proper and practical encapsulation

I have been working on refactoring old code and found a lot of instances of the following type of situation: There is a master object which we call "Application" and there is only one of these. The ...
0
votes
0answers
60 views

Should I ever reset object state?

I have a series of TextBlocks which are drawn on frames to make a video of a book. I do it when user click on Make Video. User may change the content of some blocks and click again on Make Video. I ...
0
votes
4answers
70 views

What's the best way to handle slightly different exceptions?

My code right now looks something like this: void throw_illegal_part_of_input_exception(char c) {} void throw_invalid_input_length_exception(int position, int length) {} void ...
61
votes
7answers
5k views

How do I take responsibility for my code when colleague makes unnecessary improvements without notice?

One of my teammates is a jack of all trades in our IT shop and I respect his insight. However, sometimes he reviews my code (he's second in command to our team leader, so that's expected) without a ...
7
votes
4answers
258 views

Best way to analyse a large class before refactoring it into smaller classes?

Foreword I'm not looking for a way to refactor a large spaghetti code class, that topic has been covered in other questions. Question I'm looking for techniques to begin to understand a class file ...
4
votes
1answer
274 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) { ...
0
votes
1answer
75 views

Are there any strong reasons to use DI for sub-classes that are known to be tightly coupled to their parent containers?

I have Product classes for Products A through Z. And each Product class has its own set of product-specific subclasses, which I'd say are tightly coupled to them, like so: //specific product class ...
-1
votes
2answers
51 views

Points to Understand Architecture of an Application/System [closed]

We are working on a knowledge transition of multiple applications (around 700). To make the process easy, I am preparing a list of key points we need to consdier for understanding the architecture of ...
3
votes
4answers
221 views

How to refactor my project to have less mutable objects? [duplicate]

There seems to be a trend towards immutable objects, and functional programming. I recently got aware about the benefits of immutability. However, I am not very familiar with this style of ...
4
votes
4answers
1k views

Refactoring: When to add a new class in the project?

When do you feel that you need a new class (maybe when you are developing or after development for refactoring purpose)? Maybe I can start from my existing variables and think how I can reorganize ...
0
votes
1answer
124 views

Writing code with language features yet to come in mind

In C#6, we will (most likely) have the nameof operator, a very useful operator for the ArgumentNullException pattern: public void M(T x) { if (x == null) { throw new ...