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
2 answers
882 views

Can a single Factory be used to create similar in purpose, but different in focus objects?

I am concerned about whether or not I am using FactoryMethod correctly. Background: I am refactoring legacy code and I have identified a pattern: there is a God Object that is created in memory,...
4 votes
2 answers
148 views

Refactoring: Self invoking function instead of Extract method ?

I'm reading the 'Refactoring' book, and i'm at the "Extract method" technique: Original code: void printOwing() { printBanner(); //print details System.out.println ("name: " + _name); ...
4 votes
2 answers
759 views

Revisiting Fowler's "Public versus Published Interfaces" article with regard to versioning and microservices

In this short article Public versus Published Interfaces from 2002, Martin Fowler distinguishes between easily changeable "public interfaces" and harder to change "published interfaces": The key ...
3 votes
0 answers
175 views

Are there downsides to writing PDO/mysqli statements into my code directly vs using my own redirect wrapper methods?

TL;DR: To access DB functionality in my codebase I currently use a custom layer throughout the code. The layer needs an upgrade in order to begin accepting prepared statements, which it currently ...
19 votes
6 answers
3k views

How to remove a function or feature when using TDD

In texts about TDD I often read about "remove duplication" or "improve readability" during the refactoring step. But what makes me remove an unused function? For example let's say there is a class C ...
23 votes
7 answers
53k views

Avoid too complex method - Cyclomatic Complexity

Not sure how to go about this method to reduce Cyclomatic Complexity. Sonar reports 13 whereas 10 is expected. I am sure nothing harm in leaving this method as it is, however, just challenging me how ...
58 votes
9 answers
10k views

How to write unit tests before refactoring?

I've read some answers to questions along a similar line such as "How do you keep your unit tests working when refactoring?". In my case the scenario is slightly different in that I've been given a ...
6 votes
3 answers
351 views

Is it better to try and implement incomplete code, or write your own?

Our application is a 6-year old legacy application made by out-of-house contractors. Occasionally we stumble upon the skeleton of something they put together but never implemented, and it causes us ...
4 votes
2 answers
5k views

Why delete method/field/function refactoring doesn't exist in Eclipse?

An operation in an interface is obsolete so I decided to delete it. It seems that there is no automatic support for such a "refactoring" in Eclipse. For me is a refactoring operation since the ...
2 votes
2 answers
49 views

Refactor using CTI or create new Entities

I'm currently developing on a rather large e-commerce application that handles multiple different business-fields. Like every e-commerce application we have a Concept called an Order which has one or ...
5 votes
5 answers
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 maintenance ...
5 votes
4 answers
846 views

Code cleanup methods and/or code coverage tools

I have an application at work, which I started work on about 7 years ago. This was my first engagement in ASP.NET web applications, and coming from a Win32 background I had a hard time adjusting. ...
1 vote
1 answer
94 views

jQuery, deferrers and "if" conditionals

How could I simplify the following code? I suspect that it can be simplified by using the $.Deferred class, but I don't know how. if (condition) { $.get('url').done(function () { done(); ...
1 vote
2 answers
102 views

Replacing buggy component with library: important to identify bug in old component before replacing?

Summary: component used to work and now doesn't, the regression happened 1+ years ago and we're not sure when, now I'm considering replacing the broken and poorly architected component with a mature ...
8 votes
7 answers
662 views

Is there such thing like a "refactoring/maintainability group" role in software companies?

So, I work in a company that does embedded software development, other groups focus in the core development of different products' software and my department (which is in another geographical location)...
27 votes
5 answers
5k views

What is the politically correct way of refactoring other's code? [duplicate]

I'm currently working in a geographically distributed team in a big company. Everybody is just focused on today's tasks and getting things done, however this means sometimes things have to be done the ...
20 votes
8 answers
1k views

Dealing with coworkers when developing, need advice [closed]

I developed our current project architecture and started developing it on my own (reaching something like, revision 40). We're developing a simple subway routing framework and my design seemed to be ...
72 votes
7 answers
10k views

How do I take responsibility for my code when colleague makes unnecessary improvements without notice?

One of my teammates is a jack of all trades in our IT shop and I respect his insight. However, sometimes he reviews my code (he's second in command to our team leader, so that's expected) without a ...
2 votes
2 answers
1k views

Definition of Top-down Refactoring / Bottom-up Refactoring

In the context of refactoring, you sometimes come across the term "bottom up approach", which makes sense in a way that you change the smallest moving parts first when refactoring. However I never ...
1 vote
1 answer
523 views

Ruby: Abusing mixin

I'm currently working with some code that IMO has abused ruby's mixin features. Given that I'm new to ruby, I wonder if MO in IMO is correct or not. My primary question is what makes more sense (and ...
3 votes
2 answers
337 views

How to stay DRY with return values

I have a bunch of repetitive C++ code that looks like this: // Compute finalOutput if possible. Return true if successful, false otherwise // finalOutput only holds a valid value if true is returned. ...
1 vote
0 answers
35 views

Refactoring Code into a MVC Pattern under the Constraint of a Library God Object [duplicate]

I have 1000 LOC that I plan to refactor into different files and functions. The goal is to be able to test the business logic independently from the visual display. Hence, I am considering an MVC ...
5 votes
3 answers
500 views

How aggressively to change in-house smart pointer to unique_ptr?

I work on a large software product which, being over 20 years old, has a number of constructs which have been superseded by language updates. One of these is a home-rolled smart pointer template ...
32 votes
9 answers
8k views

Why are deadlines always so short? [duplicate]

I'm a junior developer in a small company (in a team of 2 developers). Everytime we are asked to implement a new feature: the deadline is set so that we just have time to do the development: there is ...
1 vote
3 answers
169 views

Should I keep "redirect only" methods in my Controller?

Controller: function indexAction() { if ($condition) $this->renumPosition($id); //LINE #1 } //Redirect only - function's sole purpose is to call another function function ...
4 votes
2 answers
1k views

Refactoring my code that depends on a renamed library method

Say third party library Beautify renames one of their methods from beauty to makeBeautiful because they want the method to be a verb and by some lack of initial planning didn't do this from the start. ...
0 votes
1 answer
603 views

Recommendations to organize code changes in GIT

I'm looking for an advice reflecting my point of view. First, I will explain my point of view. My point of view I'm working in a big company as a C++ developer, we are using GIT. I'm going to make a ...
2 votes
1 answer
106 views

Refactoring a class which exposes way too much of its internals

I've got some legacy code (both in the sense of code that has no tests, like the definition given in Working Effectively with Legacy Code, and of relatively old code) that I have to extend. There is ...
2 votes
1 answer
1k views

Initializing composite classes in Python

I am writing a Python system where I have a major class(PlayerModel) that has two another classes as members (StateModel and ActionModel). I was wondering, what is the correct way to initialize such ...
1 vote
4 answers
210 views

How to name functions that use conditionals in refactoring [closed]

Consider this bit of code : private Norf foo(Baz baz) { // ... // Logic on baz // ... if (baz.color == Baz.BLUE) { // Do this thing } // ... // More logic // ...
7 votes
1 answer
276 views

Is there a term for splitting a function into "prep" and "do" halves?

I'm revisiting old code, and I noticed that the main logic is in one method, which is longer than I'd like (~60 lines). So I split it, and there's a natural seam on which to do so: the first half ...
0 votes
2 answers
88 views

Preparing to remove a tightly coupled service provider out of source code [closed]

I'm working on a huge legacy codebase that uses Bing Maps API as a service provider and I have got the task to scrap Bing which is the foundation of the software and has been referenced through the ...
29 votes
6 answers
8k views

Is there a design pattern to remove the need to check for flags?

I'm going to save some string payload in the database. I have two global configurations: encryption compression These can be enabled or disabled using the configuration in a way that either only one ...
6 votes
6 answers
4k views

What deters developers from using automated refactoring tools? [closed]

I was having a discussion with my colleagues about using the automated refactoring tools in IDEs (Eclipse, NetBeans, IntelliJ, Xcode, Visual Studio, etc) and was surprised that many of them were ...
18 votes
8 answers
4k views

Refactoring a long method which is based on large number of switch cases [duplicate]

We are using Java as a backend development language. One year back, we wrote a method which uses switch cases based on Enums values. Since we are continuously adding enum members and according adding ...
21 votes
4 answers
13k views

How does having too many instance variables lead to duplicate code?

According to Refactoring to Patterns: When a class is trying to do too much, it often shows up as too many instance variables. When a class has too many instance variables, duplicated code ...
1 vote
1 answer
166 views

Refactoring pattern Split Temporary Variable vs collection variable

We are using Java as a backend development language. We are using a List variable as method() { List recordsList = new ArrayList<Record>(); . . recordsList.add(records); . . ...
3 votes
3 answers
305 views

How to refine the architecture, look for better solutions and not to spoil relationship with the team?

TL;DR What are the good practices of iterative search of a better solution? Well, if I knew everything in advance and could immediately suggest 146% correct solution for a given context, I'd probably ...
3 votes
1 answer
575 views

Single Responsibility Principle : Proxy Pattern for refactoring

However, in cases where the tests did not force the separation, and the smells of Rigidity and Fragility become strong, the design should be refactored using the Facade or Proxy patterns to separate ...
1 vote
0 answers
142 views

Having a globally static cached list without breaking encapsulation?

I have a couple wrappers around third party APIs that allow me to retrieve information from certain web services. Querying these services can be rather time intensive, so in my older version of my ...
8 votes
1 answer
1k views

Refactoring byzantine payment processing code on a limited budget [closed]

I've been working on a large Ruby on Rails application for several years. It was inherited in a poor state but most of the production bugs have been ironed out with time. There are some sections that ...
7 votes
5 answers
3k views

Refactoring three very similar classes using inheritance?

I'm currently working on refactoring the code-base for one of our services. I'm been going through reviewing everything, and I feel it's a bit scattered, and could probably adhere to OOP principles ...
3 votes
1 answer
3k views

Refactor class (extract methods) in a main / helper classes

Simply spoken, one of my c# classes got too big and I'm currently splitting this class in several subclasses by clustering semantically related methods (actually actions, which do side effects). So, ...
3 votes
3 answers
329 views

Which pattern can I use for doing computations involving similar yet different object subtypes?

How do I design code that has two qualities: uses similar but different subtypes of an object uses similar but different types of computation on the above objects Example I am refactoring this ...
32 votes
9 answers
4k views

How clean should new code be? [duplicate]

I'm the lead designer in our team, which means I'm responsible for the quality of the code; functionality, maintainability and readability. How clean should I require my team members' code to be if ...
5 votes
2 answers
2k views

Can I wrap a collection with a static class and still call it repository pattern?

I couldn't find a single example about repository pattern using something else then a database. My goal is to have a global static repository that stores some objects in memory. I don't want it to ...
0 votes
1 answer
2k views

Switch complex WinForms app to WPF MVVM

This question is connected with my older question C# Application GUI design dependent on configuration. I have built quite big WinForms application working in industry for a few years. It ...
10 votes
7 answers
2k views

Should all development, including refactoring work, be accompanied by a tracking issue?

The debate: Should all development, including refactoring work, be accompanied by a tracking issue? (in our case, Jira) The common ground: Our primary goal is quality. A working product, every ...
0 votes
2 answers
3k views

Refactoring method with nested loops and 6 variables [duplicate]

I have a method which implements a small section of a (complex) algorithm. This algorithm has taken me several weeks to perfect and is by far the fastest method I can find. The method in question has ...
8 votes
2 answers
6k 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) { ...

1
6 7
8
9 10
15