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

0
votes
1answer
60 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 ...
0
votes
2answers
76 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 < ...
-2
votes
0answers
64 views

How to improve understanding of the code written by someone? [duplicate]

I'm now working on an iOS (Objective-C based) project which is already developed. Now i need to maintain the whole project. Since i know few basics of iOS programming, now its being difficult for me ...
2
votes
2answers
251 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
262 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 ...
35
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 ...
28
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
207 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 ...
4
votes
4answers
873 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 ...
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 ...
83
votes
15answers
7k 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 ...
2
votes
2answers
153 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 ...
2
votes
0answers
68 views

Fixing years of bad coding [duplicate]

Last year I got my first job with an I.T. company developing industrial Android applications. Unfortunately, when I got there and started working with the code base I was repeatedly confronted with ...
4
votes
4answers
178 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
58 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
66 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 ...
7
votes
4answers
208 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
228 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
72 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
vote
2answers
80 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 ...
3
votes
4answers
205 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 ...
0
votes
1answer
121 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 ...
1
vote
2answers
563 views

How can i get around of infinite circle of technology change [duplicate]

I have been in web developement for 6 years. I am facing one big problem and i want to know how can i get rid of it. There are many personal projects like web application which i want o build. As an ...
1
vote
0answers
140 views

Unsafe redundancy refactoring in ReSharper 9.0? [closed]

Considering the following scenario: public class A { ... public virtual void Foo() { ... } ... } public class B : A { public void DoSomething() { ... base.Foo(); ... ...
4
votes
1answer
236 views

Derive from a base class but not include a condition in the base class's method

The current code looks like this: public class Details { Public void Populate() { WriteChapterDetails(); } public void WriteChapterDetails() { if ( ...
5
votes
2answers
463 views

When to fix something that is “wrong” but works fine

Short version: I wrote some code that is not done "the right way" because, when I wrote it, I didn't know how to do it. Now that I know how to do it "the right way", how do I decide how to fix it? ...
0
votes
1answer
66 views

refactor by inheritance or composition for large class that depend on common state [duplicate]

I have a huge class (>1000 lines), in which all methods depend on a small set of attributes in that class. I can think of 2 quick ways of refactoring. I keep it as a huge object, but split related ...
5
votes
1answer
117 views

How to use OO Design to Refactor a Library with Functions that are specific Product-aware

I have a class that acts as a library of functions for various products. To compute its data, the function currently needs to be aware of all product names. Depending on which product calls the ...
0
votes
2answers
128 views

Classic ASP to Java UI Conversion

My question is based on a business model of a financial services organization that currently is supporting applications that are a hybrid mix of Classic ASP and Java, with some JSP’s already in some ...
1
vote
4answers
195 views

What is the efficient way to eliminate duplication? Design patterns?

I have a helper class which has a method that perform some checks against a field in a model. I have two models, ModelA and ModelB, they have some similarities but not all. One of them is they both ...
1
vote
1answer
87 views

Lookup pattern as a way of passing global references

I am looking at some legacy code in java that uses the Service Locator pattern as a way of passing global references as opposed to passing them over and over again through method arguments and I am ...
51
votes
11answers
5k views

How do I avoid cascading refactorings?

I've got a project. In this project I wished to refactor it to add a feature, and I refactored the project to add the feature. The problem is that when I was done, it turned out that I needed to make ...
6
votes
5answers
2k views

How are financial organizations planning for the degradation of old programming languages such as COBOL? [closed]

I know that some financial organizations still use "dead" languages such as COBOL. I'm wondering what will happen in the future, when almost no one will program in those languages, and the ...
0
votes
1answer
207 views

Suggestions on refactoring a poorly written ASP.Net MVC web application [closed]

I have recently "inherited" a project written in ASP.Net MVC which has quite a few issues and I'm looking for suggestions on how to go about refactoring the code. The technical issues found so far ...
1
vote
2answers
108 views

Refactoring: reducing duplication without creating flags

I don't know how to refactor a piece of code that differs from other in the number of conditions checked on an if clause. Let me show you a real world example I'm facing right now. The only ...
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 ...
1
vote
2answers
196 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 ...
3
votes
3answers
446 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? ...
1
vote
1answer
161 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 ...
2
votes
1answer
338 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
65 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
239 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 ...
1
vote
0answers
112 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
128 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
183 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 ...
2
votes
1answer
128 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 ...
18
votes
6answers
882 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 ...
1
vote
2answers
235 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 ...
0
votes
2answers
171 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 ...
3
votes
3answers
252 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 ...