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
-2
votes
0answers
23 views

How to optimize the check for data types before building an object?

I'm trying to build an object, which uses different methods based on different data types. I.e. it differs from withBooleanValue,withStringValue and withDateValue depending on the data type. What I ...
0
votes
1answer
58 views

Event sourced persistence and data model refactoring

I've been working on a system that is using event-sourced persistence for it's data model. It is using a standard model of sequence of events with aggregates being rehydrated from those events and ...
0
votes
1answer
40 views

Refactoring powershell codebase to support multiple environments

I come from a Java background, but now I'm supporting a PowerShell code base. In the PowerShell code base there are multiple modules that were written against a certain Azure environment. Now, we ...
5
votes
6answers
362 views

Structuring a long sequence of operations

Imagine a production line - say, building a car. Starting from the beginning, a long, defined sequence of operations takes place, and at the end a car comes out. At various points along the way, ...
17
votes
9answers
4k views

Which object should have the method?

I am trying to create an object model for a user and a chatroom. I'm stuck on where to place certain functionality when the objects collaborate. At the moment all the functionality for the User is ...
-2
votes
3answers
123 views

Code optimization tool [closed]

Would it be possible to develop a program that could optimize algorithms, detect design patterns and then rewrite the code? For example: Detect a Bubble sort and transform it into a Quick sort or a ...
3
votes
4answers
313 views

Isn't refactor on an existing and fairly new module a normal practice in software product development?

Currently when working in a scrum team in a software service company, who has a clean business domain. I am working on adding new features to an existing module. As the existing module is legacy, and ...
2
votes
1answer
82 views

Are there any C++ command pattern implementations which make it easy to add additional functions and their parameters

For my situation I have a device receiving string commands such as turn_on, pump, etc. Some of these commands also have arguments attached to them such as an int. I have methods like this void turn_on(...
92
votes
9answers
18k views

Is it the correct practice to keep more than 10 years old spaghetti legacy code untouched without refactoring at all in big product development?

I have been in two software product houses for three years in a row. The first is a small company maintaining a fairly small management system with a monolithic legacy code base (almost twenty years). ...
5
votes
7answers
390 views

If an entity of the business changes its name, should there be a refactoring?

This question comes when there are changes during development and some entity of the business changes its name or its purpose. When it comes the time to develop, it can get very confusing during ...
-1
votes
1answer
91 views

Refactoring: Pythonic way of reducing the subclasses?

background: so, I am working on an NLP problem. where I need to extract different types of features based on different types of context from text documents. and I currently have a setup where there is ...
1
vote
0answers
34 views

Applying Replace Conditional with Composition in functional programming

If I am writing in a functional style and want to use the Replace Conditional with Composition refactoring pattern on a switch or a long chain of if/else if/else if/..., how do I approach it? I ...
-2
votes
1answer
70 views

Refactoring nested if-else interface method in Java8

I have the below default method in an interface and it seems to be pretty complex because of the many if-else conditions. default void validate() { Application application = application().get(); ...
4
votes
2answers
206 views

Should the name of a method be less descriptive if its class/module alread is enough?

I have a module or class Random and in it there's a method called generate(). A client will always call it as res = Random.generate(). And from the inside, obviously, it can be called simply as ...
2
votes
2answers
235 views

Unit Testing Controllers without Mocks

I've done a lot of test writing using Mocks, and so I've learned that it makes refactoring difficult due to implementation coupling inherent with Mocks. I've done a lot of reading on the topic tonight,...
2
votes
4answers
242 views

Altering the state of a composed class by its composing classes. Is there any rule or principle for not doing so?

In other words, is it good to define the method that removes an element in a collection inside the class representing the element, considering a composition relationship? Something like: listElement....
-2
votes
1answer
78 views

Code Base Analysis

Does anyone know of a methodology that can be used on a project file tree to identify dead files, dead code, unused libraries, etc. I have been thinking about this for some time as I seem to inherit ...
0
votes
4answers
203 views

C# refactoring with inheritance

I have two classes which contains almost same method. How can I refactor this with inheriting one class by other class. class A{ public void run(){ // task 1 // task 2 // task 3 } ...
2
votes
1answer
80 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
76 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 ...
0
votes
1answer
54 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
292 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
118 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
145 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 ...
-4
votes
2answers
93 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
155 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
193 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
2answers
172 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
45 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
63 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
131 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
99 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
48 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
252 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
49 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
210 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
226 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
149 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
32 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
160 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
346 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
353 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
92 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
160 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
9k 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
7k 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 -...

1
2 3 4 5
14