Questions tagged [refactoring]

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.

Filter by
Sorted by
Tagged with
0
votes
1answer
60 views

How should one perform a major refactor in parallel with continuous delivery of new features?

Suppose you've been hired to perform a major refactor/rewrite of a large project that is already in production and maintained by a very small team. The scope of this rewrite is to the point where you ...
0
votes
2answers
42 views

How to share entity classes (JPA) among projects, where not all have DB access?

So, I have project in which several WebServices will be created (REST). For the sake of simplicity, Lets name them A, B, and C. A and B handle different tasks, but both of them consume C, which is the ...
-1
votes
1answer
37 views

What to do with a legacy code base with no unit tests and complex architectural structure [duplicate]

I have been working for my company for almost a year now and been primarily focused on adding features and maintaining two 15+-year-old WPF Projects and one 20+-year-old WinForms Project. The ...
5
votes
2answers
276 views

How to clean up a business logic class that does too many things without injecting a ton of classes into it?

Let's say we have business logic to perform in an MVC framework after a user submits a form: class BusinessLogic: def sendDataTo3rdPartyApi(self): # do stuff def validateResponse(self)...
3
votes
1answer
114 views

Is there a pattern for choosing one of a set of options at random when their selection criteria are equal?

I want to choose between several options, and if the criteria I'm using for selection happen to be equal, I want one at random (reasonably so, so it's equal-chance each time, rather than arbitrary). ...
3
votes
2answers
135 views

Refactoring for removing explicit object construction inside class

I'm wondering if there's a standardized name for the following refactoring: class Foo: def do_something_awesome(self): my_bar = Bar(42) return my_bar.reticulate_splines() Here class Foo is ...
-3
votes
2answers
80 views

Is there a better way to write the logic for handling “close plus open” and “partially close” trades?

I am writing a paper trading system, and what I have works, but I can't help but feel that there's a better way to partially close a stock position; what I currently have seems a little overboard. ...
-3
votes
3answers
139 views

How can I tactfully point out that a colleague's work is bad? [closed]

As my first job, I joined a startup with a small number of developers. I mainly work with this one other person -- let's call him Paul for now. We are the only two devs on our team. He joined the ...
1
vote
3answers
178 views

Approach for rewriting a large, mission-critical method

Context: I am a new hire out of university at a large software company tasked with either refactoring or re-writing a large legacy method (~500 lines, ~2000 lines expanded with private method calls) ...
-1
votes
1answer
90 views

Won't a characterization/regression test fail when a bug is fixed?

Let's assume that you are trying to refactor a legacy code to make it easier to understand and more testable, how can you do that? In the book "Working with Legacy Code", a characterization/...
2
votes
1answer
40 views

State Pattern: duplication in State and Context

Wikipedia gave an example of State Pattern: Define LowerCaseState and MultipleUpperCaseState, both inherite from State. interface State { void writeName(StateContext context, String name); } ...
-4
votes
1answer
43 views

How to refactor Global variables?

I found this previous question that addresses the issue. The question is: How do I deal with global variables in existing legacy code (or, what's better, global hell or pattern hell)? My question ...
2
votes
2answers
119 views

Large method with nested switch case(s) refactoring (Java)

Essentially I've got a bunch of formulas in two giant methods in a class designed to do math transformations and evaluations to multiple inputs. Where the inputs are actually lists of inputs (as there ...
2
votes
0answers
79 views

How to separate a serialization code from application in a large c++ project

I'm working on a fairly large c++ project which uses boost's serialization. The issue that I have with the way it is currently organized is that serialization is weaved into the main source code on ...
5
votes
2answers
2k views

Best Practice for Adding an Additional Parameter to a Function

I'm currently working with a very large system and have been asked to add an additional parameter to a method that's called from over 200 different places directly. The method signature looks ...
-3
votes
1answer
47 views

Different input param for the same logic flow

I'm trying to find the best design approach to handle a design change in a new project I'm working on. At the moment, the flow runs and makes some calculations based on a parameter which is used. ...
2
votes
5answers
246 views

Splitting class responsibilities without exposing private data

I'm struggling to find good ways to split up classes without exposing private data. Most articles I read about SRP seem to ignore how the new classes that take on the separated responsibilities access ...
0
votes
1answer
71 views

Refactoring and simplify this infrastructure building code [closed]

I have a piece of code (a Facade) that creates every single infrastructure component on aws. private void synthesizeStack() { Deployer<Vpc> vpcDeployer = new VpcDeployer(this); Deployer&...
0
votes
0answers
42 views

CK Metrics - Lower Complexity by Refactoring

I'm suppose to identify 3 CK metrics and the most appropriate class to refactor so as to increase encapsulation, modularity and reduce the complexity of the following project According to my ...
1
vote
1answer
190 views

Using “magic” strings for single-use error reasons?

I'm writing a fairly large piece of logic, during which there are 6 points where things could go wrong and execution should stop after logging the error. The error is also stored in an object. ...
1
vote
2answers
133 views

Refactoring multiple for loops on same list in different methods

I have a code that is something like this in a class string method x (){ foreach(a in alist){ //do something } return string; } integer method y (){ foreach(a in alist){ //do ...
0
votes
2answers
104 views

Refactor the method which has the sequence of the similarly looking blocks of code to (or towards) the design pattern(s)

I need some help to understand if the code below could be refactored to something less straightforward, less repetitive and more towards any appropriate pattern. What I feel uncomfortable with in ...
2
votes
2answers
141 views

Refactor approach for huge if else Clutter based on many independant conditions

Currently I am cleaning up hard to maintain and test if else clutter which is based on conditions which have to be checked in isolations: What is the basic semantic of the conditions? Big Entity ...
0
votes
0answers
27 views

Gateway aggregation is only for microservices?

I started to work in an existing Angular app that consumes a monolithic Web API writen with .NET CORE. This API has dozens of controllers(routes). In one of the main screens, when one specific event ...
1
vote
2answers
130 views

How to refactor duplicated functions with only one difference in parameter list

I've got 2 near-identical functions (NodeJS). One of them queries DB for shop information by its phone number, while the other one queries by its id. I'd like to know if there's a clean way to merge ...
-2
votes
4answers
342 views

Is judicious & plausible selection of class fields a valid refactoring step?

I'm a great fan of refactoring but I've been wondering about the issues raised by refactoring. Fowler advises refactoring to make code readable to all users to make the code structure more sensible, ...
6
votes
2answers
350 views

How to avoid changing dozens of classes and interfaces when adding an argument to a method used in dozens of classes and interfaces?

On several occasions, I was faced with the following design issue that I don't know how to resolve. Imagine, for instance, an application which at some point receives a JSON object from an API. Before ...
2
votes
1answer
91 views

Multiple clients of the same server - how to refactor while keeping the benefits of current architecture?

Background I have a system that comprises of 3 components: a web application that displays data and allows data manipulation by users (React) a server application which serves the data to the web ...
1
vote
1answer
85 views

How to add supporting information to the existing java object?

Is there a way or design pattern to add supporting information to the existing java object? Example I have a model class Parent and it has child models. Its nothing but hibernate entities with parent-...
2
votes
3answers
154 views

What options are available to replace an `enum` with a multi-type solution?

A Quick Note I know the question title is a little odd but I haven't had much caffeine this morning so I'm having trouble thinking clearly right now. If you have any suggestions for a better title, ...
35
votes
10answers
8k views

In TDD, should I add unit tests to refactored code?

While refactoring my code using Test Driven Development (TDD), should I keep making new test cases for the new refactored code I am writing? This question is bases on the following TDD steps: Write ...
35
votes
11answers
6k views

Unexpected Code Coverage Reduction

I am adding unit tests to some existing code which initially was not tested at all. I have set up my CI system to fail builds where the code coverage percentage is reduced compared to previous build -...
0
votes
1answer
255 views

How important is it to have a consistent technological stack? [closed]

I'm trying to make a browser MMO game as a hobby project. Currently, the server-side code is written in ASP.NET Core (this was not my choice; the game started as an academic project and the prof ...
2
votes
1answer
90 views

How to Avoid Copy Pasting Repetitive Log Calls

Currently working on a Go project of about 10k lines of code. Within the project, there's a logging library that requires a couple steps of initialization in order to actually write to the log ...
4
votes
2answers
355 views

How to avoid duplication in a for loop when “initialization step” is identical to “update step”?

I often find a situation where I need to write duplicate codes in a for loop, where the "init step" to identical to the "update step": // duplicate `next()` for (let x = next(); p(x); x = next()) { ...
-1
votes
1answer
106 views

How to generalize this method for its duplicate/common logic?

I've a method that apparently has quite some duplicate logic, I'd like to generalize it so that their duplicate logic could be shared and reused, also make my code more extensible for future additions....
3
votes
0answers
32 views

Decoupling redux reducer tests from state shape

Recently I have been refactoring state shape in a fairly large redux application, and I have found that one of the obstacles to doing to is that the tests for my reducers clearly have a lot of "...
1
vote
1answer
242 views

What can I do to make adding new concrete classes (of abstract/interface classes) easier across the code base?

A real (but simplified) example from the program that I'm currently working on. We have an abstract Request class and two classes that extend it: FooRequest and BarRequest. They both have dao's used ...
-2
votes
1answer
566 views

How to avoid code duplication in this situation?

Case: Several methods with same params validation inside, like: public Response method1(...params...) { if (someCondition) { //do some stuff with side effects ... ...
2
votes
2answers
291 views

How to gradually refactor a Map with string keys to use enum keys?

I'm considering refactoring some Java code that passes around objects that implement the interface Map<String, Object>. The strings are all (as far as I know) from some fixed list of string ...
1
vote
3answers
230 views

Shifting from Anemic Domain Model to Rich Domain Model

I did a couple of simple projects following Anemic Domain Model . Now I am trying to do the similar type of projects in Rich Domain Model. But I am confused in implementations. Previously , I used to ...
1
vote
1answer
144 views

How to remove redundant tested code?

Say I have a controller public function someAction(){ $something = Helper::something(); } And I have a test to check Helper::something()returns/does whatever it should. Down the line I refactor ...
1
vote
1answer
126 views

One API used by multiple clients with small variation in the flow

I am working on refactoring codebase for a JAVA API thats used by multiple clients. Though the api provides the same overall functionality for all clients, actual flow changes a little bit between ...
0
votes
2answers
116 views

How to initialize base class property once instead of passing it from all derived classes?

I have a small library where I am performing 1 long running operation and based on that operation,I am saving some data inside database tables.Now this is small library which does not include alot of ...
1
vote
2answers
263 views

Refactor namespaces in a library while keeping backwards-compatibility

We developed a generic .NET library for our line-of business applications. This is what our namespace/class structure looked like 5 years ago: ... AcmeCorp.Tools.ExcelWriter AcmeCorp.Tools....
0
votes
1answer
302 views

Refactor multiple “if” in C#

for (int i = lstReportCount - 1; i >= 0; i--){ if ( (input.ServiceTypes == "1" && lstReport[i].A == 0) || (input.ServiceTypes == "2" && lstReport[i].B == 0) || (input....
1
vote
2answers
114 views

Best practice when creating classes that are solely in charge of the creation of other objects i.e. factories?

I often find myself creating classes that I suffix with 'Factory'. These classes tend to be solely in charge of the creation of a specific class or set of related classes. However I've always felt ...
1
vote
1answer
223 views

Best pattern to solve problem where objects only differ in one attribute

As I am maintaining and extend a software system in Java, I saw a colleague (who left due to retirement) implementing a table with a generic approach. This approach is unluckily bound to tables (ui-...
-1
votes
2answers
119 views

Common way to name methods with same name as desired variable? [closed]

I frequently find myself pulling up helper methods in order to make my code better, but end up with duplicate method names. Is there a standard way to name such methods without getting duplicate names?...
4
votes
5answers
277 views

Should opportunistic refactoring happen in a different branch to functional changes

I'm not talking about the usual refactoring of new code you do as part of a development. This is more Boy Scout Principle type changes. While I understand why they're all made in the same branch, it ...

1
2 3 4 5
14