Questions tagged [refactoring]

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

3
votes
2answers
249 views

What is the protocol to follow if I wish to make significant changes to software in someone else's public github repository?

For example, I find myself using software X. Software X has a github repository. I find that I can make a lot of serious refactoring changes that are not small, and reconfigure the entire repository ...
2
votes
1answer
238 views

Refactoring in A Legacy System: Good vs Bad Technical Pushback

I am noticing a weird mentality, when it comes to refactoring code, and I am not too sure about how I am perceiving it. Overview of the current project: A web application used as an extension to an ...
0
votes
1answer
94 views

How to approach unorthogonal system?

I work on a software platform that is homegrown and, for the most part, used internally in the company but it is deployed in facilities across the globe. This system runs on a specific set of ...
0
votes
2answers
198 views

How to handle different type of error in one function

Context I'm working on refactoring a program that saves data in a DB. This program has a Graphic Interface. The programmer who did this program ( the one i'm working for) would like me to make this ...
2
votes
2answers
217 views

Object Oriented Re-Design/Re-Write

Let me begin by stating I have already reviewed the following related questions, and just wanted to showcase the software architecture which I have inherited to see how opinions may vary. When is a ...
3
votes
2answers
559 views

What is the right time to go for Code Refactoring, not optimization?

I've been working on a Python(Django)/JavaScript(AngularJS) based application for some time now.(I learnt all of these on the way, had previously been a Java only programmer)and have hit moments where ...
2
votes
6answers
1k views

How to avoid changing the signature on a well-used method?

The Existing Code I have a C# project with about 45000 lines of code. It has a utility/helper class which contains static methods which make it easier for my code to work with PDFSharp/Migradoc to ...
-2
votes
4answers
512 views

Best practice to avoid or refactor casting base type to derived class

I have an example about design patterns that demonstrates the adapter pattern. But I see casting to derived class here. That is not very good. If I meet such code in my practice, what is the best way ...
0
votes
0answers
66 views

Creating a common ancestor form in Visual Studio

I have 5 forms which in hindsight should have an ancestor descended from Form. Unfortunately, the common elements of the forms is a splitContainer and a listbox in one of the containers. Each form ...
3
votes
2answers
437 views

Correct way to extend a hierarchy tree

I have the following tree currently to be implemented in Java. My problems are the following: How can I go about addressing the fact Admin needs to have all tier 4 logic from both branches of the ...
32
votes
10answers
7k views

Is “Parent x=new Child();” instead of “Child x=new Child();” a bad practice if we can use the latter one?

For example,I had seen some codes that create a fragment like this: Fragment myFragment=new MyFragment(); which declares a variable as Fragment instead of MyFragment , which MyFragment is a child ...
1
vote
2answers
115 views

How do I centralize data access between a php web service and a nodejs JSON API service?

I have a php web application that is written with traditional architecture with templating, controllers and ORM models. I also have a nodejs JSON API web service that accepts incoming connections and ...
1
vote
1answer
110 views

Refactoring code dependent on external class

I have a class similar to ServletFilter which has multiple validation on the input request class TokenHandler implements SomeHandler{ Response handle(Request request){ if(paramXMissing(request))...
1
vote
2answers
72 views

Maintainable methods for taking a standard plugin and repackaging one, slightly modified, small piece of it into a custom plugin

A little background on the system I’m dealing with: analytics platform --comprised of--> OSGi plugins --comprised of--> Java package(s) --containing--> unit(s) of functionality each with independent ...
4
votes
4answers
627 views

Is removing duplication worth it when it doesn't reduce code size?

Yesterday, I removed duplication in a file. The code was performing translations in a grid[i][j]. The duplication was between the code for the i-axis and the code for the j-axis: For instance, I ...
0
votes
2answers
463 views

Does “refactoring” mean that you modify the entire design iteratively? If not, what does it mean? [closed]

I was reading software engineering a practitioner's approach when I came across this question. I think the answer is no but I don't have much of a valid reason so I would like to hear other people's ...
147
votes
13answers
24k views

Should I refactor the code that is marked as “don't change”?

I am dealing with a pretty big codebase and I was given a few months to refactor existing code. The refactor process is needed because soon we will need to add many new features to our product and as ...
1
vote
2answers
155 views

Does sending parameters around inside a class suggest that I should refactor to a new class?

I have noticed a pattern when I refactor my code for readability. When I refactor a method into several smaller methods, I often have to introduce parameters which sometimes (too often) makes the code ...
1
vote
0answers
69 views

How to better factor classes that switch on type code

We have a persistence backed object, and it has a version field in the database. Assume there's lots of unrelated code in this class. # # We're branching on this "version" field, and we return one # ...
2
votes
2answers
207 views

Should I refactor up or down the callstack?

Should one make a code change by beginning to refactor at the "entry-point method" or the "inner-most method" of a call-stack? A colleague and I were talking about a code change that would go through ...
3
votes
2answers
2k views

How to refactor functions?

Let's say I want to have a function to load a project's data from both a json and a file path, the first idea which comes to my mind would be having a couple of functions such as: def ...
1
vote
0answers
104 views

Getting a free-wheeling project ont the right track… DDD? [closed]

As I said in recent other questions, the CMS we're developing at work is becoming a huge mess that's getting everybody lost (we started joking about "not caring about it anymore" with some coworkers......
1
vote
3answers
1k views

How to DRY refactor several similar functions?

I was assigned a refactoring. We have several modules having similar functions with some differences. My task is to extract common portions of code for DRY principle. I am a little lost how to do it....
0
votes
3answers
284 views

Bug Fixing Code With No Tests

I am regularly given code with bugs in it and told to fix the bugs without introducing any more. My approach is usually as follows: Identify the bug's issue, e.g. method is returning an empty list ...
1
vote
1answer
308 views

Is Design for Testing (DFT) more important than Test Driven Development (TDD) in principle?

Design for Testability is a well-known topic in digital logic. The idea is that it is difficult to exhaustively exercise some hard-to-reach parts of complicated combinational logic unless seams are ...
59
votes
2answers
7k views

Writing tests for code whose purpose I don't understand

I recently completed a black-box refactoring. I am unable to check it in, because I can't work out how to test it. At a high level, I have a class whose initialization involves grabbing values from ...
5
votes
3answers
131 views

Making incremental and future required/compatible changes first without change of behaviour: what's this called?

I have a method of coding/refactoring that I now automatically do, but I realise I don't know what it's called. If I am making a change, and realise there needs to be a change to some existing code, ...
7
votes
2answers
312 views

Is practice of using Annotations detrimental to code quality and longer term code maintenance?

With Doctrine annotation processing engine for PHP, and Annotatons being used for Doctrine Entities and for Zend Form, and possibly other things, and use in other languages as well, it looks like ...
6
votes
1answer
383 views

How to efficiently implement data-heavy screen updates in a web application?

Imagine an engineering type web application where there is a screen that displays around 100 of unique data values. The user can "page through" the screen by clicking Right/Left arrows, and the screen ...
-3
votes
1answer
122 views

Refactor multiple if tests [closed]

I have a class constructor that needs to perform a couple checks. It is checking a file for the occurrence of a few tags. I use a function that checks for the tags and returns a boolean value ...
4
votes
4answers
620 views

When redesigning an application that uses Metric & English units for data, how do I store data in datatabase?

In my application users compute some engineering data (physical quantities like lengths, and weights). Currently the core formulas work on and assume English system, but user can select English or ...
13
votes
3answers
373 views

Multitudes constructing one implementation. DI hopeless? Use service locator?

Say we have 1001 clients that construct their dependencies directly rather than accept injections. Refactoring the 1001 is not an option according to our boss. We're actually not even allowed access ...
13
votes
1answer
6k views

Where does refactoring belong in GitFlow branch naming model?

I recently started working with GitFlow model as implemented by bitbucket. And there is one thing that is not completely clear to me. We try to regularly address our technical debt by backlogging, ...
0
votes
1answer
166 views

Design improvement - C

Below is the design, that is implemented similar to design used in Linux/net/socket.c. Below design provide List abstraction, where, list.h provides List interface, show here Background: ...
4
votes
1answer
564 views

Impacts of using class_alias() to maintain backwards compatibility in PHP

Scenario: An open-source PHP project that has existed for several years has too many classes in the main namespace that we want to refactor some of them into another namespace, but we have a widely ...
1
vote
1answer
131 views

Refactoring List abstraction - C

Below is the working List abstraction design, List is a generic abstraction holding any type. Below is the code directory structure. Currently symbol table(ST) and file api fileIO is using List ...
4
votes
5answers
243 views

What is it like to change the underlying database on a significant real-life project?

Have you ever seen a significant non-theoretical project where the underlying database engine had to be changed? Was it a major undertaking, taking months of work, or was it conceived and done in a ...
4
votes
2answers
204 views

How do I know when to refactor global database query calls, and when to leave them alone?

I have the following global statement calls sprinkled throughout my PHP legacy codebase: $jobnumber = db_quick($sql); db_query($sql); That is, those function calls have been initialized in the ...
4
votes
5answers
597 views

Should I refactor this database? How can I do it?

Firstly, some context. I'm working in a project with more than 10 years of development and without any documentation. My task now is to create a comprehensive documentation for the database (it is a ...
1
vote
2answers
455 views

Assigning local variables in a bulk way

I've been trying to mull over a question I am not sure how to solve and it probably has a simple solution however I am trying to work out a simple solution. The following scenario is as such. Let's ...
-1
votes
1answer
102 views

What is the reason behing Tuples instead of HList in akka-http

As I can see in recent releases of akka-http, successor of spray, spray-routing's approach of using shapeless HList was replaced in favor of self-included Tuple What is the motivation for this ...
1
vote
1answer
207 views

Refactor settings module to settings object (python)

I have a small python application (about 6000 loc), where I keep my settings in a seperate module, settings.py. As the application grew, I started to add tests. Now after having more and more tests, ...
3
votes
2answers
133 views

One function to produce a couple or a function per item?

I have a dilemma. Let's say I have an AST that describes some grammar, for instance. I can write a function to stringify this AST back into human-readable BNF form or generate a parser from it. I can ...
2
votes
1answer
573 views

How to reduce “mapping” code?

I have two components, both are a parser/builder pair. So component A can parse A and build A, component B can parse B and build B. A and B both contain different entities, which are extracted by the ...
2
votes
1answer
523 views

How should I reorganize an existing TFS source control repository?

My employer uses TFS VCS as more of a shared storage location for source code rather than source control with clear policies and branch owners to help organize things. I've been given a mandate to ...
208
votes
16answers
44k views

My boss asks me to stop writing small functions and do everything in the same loop

I have read a book called Clean Code by Robert C. Martin. In this book I've seen many methods to clean up code like writing small functions, choosing names carefully, etc. It seems by far the most ...
0
votes
5answers
222 views

When creating time estimates for features, is there a standard percentage to tack on for potential refactoring?

Note: I get that refactoring is something you do along the way, you don't treat it as it's own "thing", or it's own specific task. I am talking about refactoring along the way, however I am not sure ...
1
vote
1answer
646 views

How to not test implementation when method returns void?

Many places in stackexchange state that you should not unit test implementations, only the public interface of a class. But what if the public interface is a method that doesn't return any value, for ...
2
votes
1answer
96 views

How to use object oriented principles to design a system that trims, selects, and formats values based on business rules, and unit measuring system?

TL;DR: I have bad, no .. horrible, horrendous code that kind of works but is a mess and is not easily maintainable. I want to redesign it and repackage it to where objects are well defined and ...
3
votes
2answers
395 views

How to keep unit tests well designed when structure of production code changes while avoiding related risk?

One of the main reasons for writing unit tests is to make sure that code still behaves the same way after refactoring. However, if interfaces change during refactoring, the tests need to be updated as ...