People who code: we want your input. Take the Survey

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
1
vote
2answers
57 views

Anemic Domain Model VS coupling and dependencies- design conflict - need an Object oriented advice

on design stage , after finding my main objects , I am always find my self writing "manager" or "controllers" classes in order to handle the connection between them. some of the ...
-1
votes
4answers
136 views

Change architecture design to API to reduce coupling

I was reading articles about TDD and I found the following one. https://blog.cleancoder.com/uncle-bob/2017/03/03/TDD-Harms-Architecture.html In order to answer this question I think someone should ...
0
votes
0answers
21 views

Optimizing methods with multiple if checks on getter values

I have a method where I fetch user input, check if certain values exist, and based on that build my own custom input object that I would use to search in a database. The code for the search method is ...
2
votes
2answers
144 views

What methods can be used to simplify mathematical expressions?

For fun, I would like to design a mathematical expression evaluator, with variables. It could simplify the entered expressions by factoring them, reducing them to a sum of simple fractions, ...
2
votes
1answer
126 views

Composition or Inheritance for classes with almost similar implementations but different input and outputs for methods?

I have the following classes, which have quite similar method implementations. Only the classes' method inputs and outputs seem to be of different types. When I put it like this, it sounds like a case ...
-2
votes
0answers
29 views

Correct semantics and naming of non-member functions for class [duplicate]

I'm thinking about changing some member functions in classes into non-friend non-member functions. (partly, motivated by writings like this https://www.drdobbs.com/cpp/how-non-member-functions-improve-...
-1
votes
1answer
76 views

rails, how to refactor nest if statements? [duplicate]

I'm working a project where I found another developer wrote a method as you see it below. How would I clean those IF statements and refactor this method. Also is it ok ti set a variable to nil ? def ...
-2
votes
3answers
137 views

How to determine if a module within an application is worth refactoring or rewriting?

We all know Joel Spolsky's famous article to never rewrite working code. How about if we don't consider overall program but a module within? Module can be e.g.: payment handling microservice in e-...
41
votes
8answers
6k views

Getting buy-in for cleaner and more structured code

I am at my company for half a year now and think that I have gotten a fair idea of their codebase. Initially I didn't dare to form strong opinions, but now I start to feel that the code could benefit ...
2
votes
1answer
112 views

Resolving lambdas that depend on each other

In the C++20 codebase that I work there are a couple of functions which have helper functions defined as lambdas. I can see the idea of locality for these helpers. By having them there in the function,...
1
vote
2answers
331 views

No trivial god-class refactoring

Consider you have the following code: class UserContainer { List<User> user; //some methods to get specific users, for example users, which are higher than 1,70meters } The User have a ...
0
votes
2answers
82 views

Good design for a class with multiple methods to test but one public method

I've been trying to refactor some existing code which is in essence a giant nested procedural call inside what should otherwise be an object oriented architecture. The entry point to the relevant code ...
5
votes
4answers
231 views

Use local or nested function for readability?

I found in the catalog of Refactoring by Martin Fowler, with Kent Beck book that they mention Extract Function refactoring. It is a good practice to wrap your related code into local functions to ...
0
votes
4answers
183 views

Refactoring two methods with similar for loops containing some unique logic

Please help me with the following code refactoring, I spent so much time researching it and there's still no clear answer on how to approach it. Any help is greatly appreciated! So, given 2 methods (C#...
3
votes
3answers
770 views

Use inheritance to make single child, smaller

We have a relatively big class. One of my colleagues thinks we must split this class into a base & child class to make it smaller and cleaner. On the other hand, I believe when we know this parent ...
0
votes
2answers
159 views

How to determine that a team is not doing enough refactoring?

I'm working my way through Refactoring: Improving the Design of Existing Code by Martin Fowler and I came across the following passage (2nd ed, p. 55, emphasis mine): To a manager who is genuinely ...
3
votes
0answers
96 views

Refactoring nested if-else statement [duplicate]

I have an app where every object is checked based on various types of business rules. For this, i used multiple nested if-else statement which was done in one class. I am not happy with this situation ...
1
vote
2answers
300 views

What is Insider Trading Bad Smell?

In Martin Fowler's refactoring book, there is a code smell named "Insider Trading" which I don't understand: Software people like strong walls between their modules and complain bitterly ...
1
vote
1answer
94 views

C# - Menu Implementation - Help writing it in a testable way

The Question: I'm developing an app in C# and am currently designing a menu which contains submenus and needs to be different depending on the category of the user. I've written the code but am ...
1
vote
1answer
45 views

Refactoring simillar integration service code block

Context: Creating a "middleware" between 2 services I have to Get data from Service Source and get it into Service ERP. There is a multiple type of Data: A, B, C. An integration process ...
0
votes
1answer
75 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
48 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
382 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, ...
19
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
154 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
324 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
128 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(...
95
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
400 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
97 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
71 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
119 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
209 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
324 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
247 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
79 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
254 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
82 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
307 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
0answers
79 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
304 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
121 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
155 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
99 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
178 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
200 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
177 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
61 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
155 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
188 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 ...

1
2 3 4 5
14