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

learn more… | top users | synonyms

2
votes
2answers
188 views

How to refactor out static members of basic classes

Currently I am working on C++ project, which can be classified as "legacy" project. A lot of poor written code was committed because of lack of experience and under the pressure of deadlines. When I ...
8
votes
10answers
2k views

How to do a clean refactoring of an If Else Code without leaving any free blocks? [duplicate]

if(condition1) { Statement1A; Statement1B; } else if(condition2) { Statement2; } else if(condition3) { Statement3; } else { Statement1A; Statement1B; } return; I would like to ...
0
votes
4answers
283 views

Usage of magic strings/numbers [closed]

This is somewhat controversial topic, and I guess there is as many opinions as there are programmers. But for the sake of it, I want to know what are the common practices in business (or in your work ...
2
votes
4answers
191 views

Considerations before rewriting a software component from scratch? [duplicate]

A piece of software is a patchwork of old and undocumented efforts. There are no comments, no documentation, and the code is hairy -- it involves Unix shell scripts that check for dummy files and then ...
1
vote
0answers
295 views

Thoughts on refactoring a generic DAO

I have designed a generic DAO in Java and am having confusion about whether to refactor it to different design or not. PS Don't say to use already existing 3rd person framework. I know there are some ...
3
votes
3answers
375 views

Is it Typical for Large Software Companies to Not Document or Refactor Code? [closed]

I have begun working at a large software company and was assigned to a project that is over a million and a half lines of code. It's part of a program suite that is sold to clients (not an in-house ...
2
votes
2answers
380 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 ...
1
vote
1answer
45 views

Refactoring from Python to Ruby with a BSD v3 license?

There is a project that is written in python which works great and is under the BSDv3 license. I wanted to use it as a base template for a ruby project instead of starting from scratch. I'd be ...
11
votes
5answers
471 views

Code repetition vs multi responsible method

I try to follow the Single Responsibility Principle (SRP) and also to omit Code Repetitions. However there are often places where there are code repetitions that are nothing more than code blocks of ...
5
votes
1answer
1k views

How do I structure a larger Flask application?

I have a relatively simple web application that is written in Python using the Flask microframework. I've really enjoyed Flask's ease of use, however, as the app has grown larger it has started to ...
0
votes
1answer
104 views

Get entities ids from two similar collections using one method

I've got two lists: List<Integer, ZooEntity> zoos; List<Integer, List<ZooEntity>> groupOfZoos; These operations will return collections of values: Collection<ZooEntity> cz ...
9
votes
2answers
345 views

Is spreading code with refactoring comments a good idea?

I am working on a "spaghetti-code" project, and while I am fixing bugs and implementing new features, I also do some refactoring in order to make the code unit-testable. The code is often so tightly ...
13
votes
5answers
1k views

Using functions as a way to stylize [closed]

Have you ever broken up a large function into smaller functions knowing that those smaller functions will not be called by more than one caller? The primary purpose of a function is to promote code ...
0
votes
1answer
114 views

unit level testing, agile, and refactoring [duplicate]

I'm working on a very agile development system, a small number of people with my doing the vast majority of progaming myself. I've gotten to the testing phase and find myself writing mostly ...
1
vote
1answer
93 views

Proper library for enums

I'm trying to refactor some code such that the display is separate from the implementation, and I'm not sure where to put the existing enums. My project is currently structured as follows: ...
9
votes
5answers
1k views

How to refactor an OO program into a functional one?

I'm having difficulty finding resources on how to write programs in a functional style. The most advanced topic I could find discussed online was using structural typing to cut down on class ...
9
votes
3answers
322 views

How to refactor when all your development is on branches?

At my company, all of our development (bug fixes and new features) is done on separate branches. When it's complete, we send it off to QA who tests it on that branch, and when they give us the green ...
32
votes
4answers
2k views

What is the term for this type of refactoring

I am sure there is a term for the following bit of refactoring, but I can't remember it and my Google-fu is failing me! The refactor moves if statements to where they are going to have most impact, ...
19
votes
3answers
1k views

Difficulties With TDD & Refactoring (Or - Why Is This More Painful Than It Should Be?)

I wanted to teach myself to use the TDD approach and I had a project I had been wanting to work on for a while. It wasn't a large project so I thought it would be a good candidate for TDD. However, I ...
2
votes
2answers
207 views

Refactoring two classes from third-party library that could have extended a base class

I have two Classes, with very similar behaviors, both from a third party library. Both needs to be populated with some value object and sent to specific queues in order for logging. Please note both ...
2
votes
3answers
139 views

Should I combine similar functions even though they are slightly different?

On an application I've been working on I have a function, connecting to a virtual machine, that can be performed two ways. The user can either select a machine from a list and click the "Connect" ...
16
votes
7answers
1k views

To rewrite or slowly refactor old C++ project [duplicate]

Our team has recently inherited a relatively large project from another company (~250k lines). It was developed using C++Builder and we intend to port the Ui side to Qt. Most of the Ui code is ...
0
votes
2answers
353 views

Refactorable God v.s. too many classe [duplicate]

So I have this problem: in order to structure my code hierarchically, for every new tiny thing, I create a separate sub-folder, file, class ... and in it one 10-line function. It is an anti-pattern. ...
57
votes
11answers
6k views

Is it a bad practice to modify code strictly for testing purposes

I have a debate with a programmer colleague about whether it is a good or bad practice to modify a working piece of code only to make it testable (via unit tests for example). My opinion is that it ...
1
vote
4answers
198 views

Until what point should I refactor? [duplicate]

What do you think until what point should a programmer refactor the code? Basically having def method do_something end Pieces of code would be handy, but they increase spaghetti code until the ...
9
votes
7answers
972 views

Temporary variables vs line length requirements

I've been reading Martin Fowler's Refactoring. It is generally excellent but one of Fowler's recommendations seems to be causing a little trouble. Fowler recommends that you replace temporary ...
10
votes
7answers
2k views

Best way to break down overwhelming code into manageable chunks?

I'm continually becoming overwhelmed by large projects, once they reach a certain level of complexity. Once I reach a certain point in a project, my progress slows to a crawl and I find myself ...
2
votes
1answer
157 views

Why does the tool offer to change the code - just because it can?

Resharper (or is it Visual Studio - it's a yellow light bulb with a tiny red filament in it) offers to "invert if" on this code: if (tItems >= 0) { return tItems; } SetTotalItemsAndTotalAmt(); ...
-1
votes
1answer
272 views

Is there a tool that visually represents all the potential paths to a particular piece of code? [closed]

As an example of what I need and why I want it, I am trying to determine how a certain value (CurTotal) is getting set (wrongly). I've come up with these notes to myself to try to understand just what ...
3
votes
4answers
730 views

Get rid of long/Complex if..else statements using Chain of Responsibility?

I've an HttpHandler, which allows users to login to a system by passing in an encrypted code. Inside the ProcessRequest it performs quite a few steps. Retrieve the encrypted code from request ...
4
votes
3answers
488 views

Is there a term for reusing code by retyping it?

I built a prototype ("one to throw away") a while ago, and I'm rebuilding it now as an alpha. My goodness, it's been worth it. I reused some of the prototype code by copy-pasting then modifying it, ...
3
votes
2answers
1k views

Refactoring c++ [closed]

I know that there are some other questions about c++ refactoring, but none satisfies my needs. I have a background in java and python programming, but now I'm approaching C++. I've read (and ...
2
votes
0answers
110 views

How to restructure Python frameworks [duplicate]

I just joined a group of five developers (non-professionals) working on a medium sized Python framework (> 50 modules, > 10.000 lines of code). The project has no documentation whatsoever and there ...
2
votes
1answer
93 views

What to name a new interface that is replacing an existing one?

We're redesigning our application's plugin interface, so we're using the Adapter pattern with our proof-of-concept design to show that the new interface will function without committing to using it in ...
9
votes
6answers
432 views

Is it better to have one method that takes a bool as a parameter or two methods with different names? [duplicate]

I'm writing a factory class for a Selenium Web Driver and I came across a choice that I couldn't figure out which is cleaner. Having two methods with the same parameter. GetWebDriver(string browser) ...
2
votes
2answers
326 views

Refactored to a fancy global variable?

I am currently refactoring an application that i built in JavaScript. The application uses a starting hour and a total working hour count in order to construct a timetable for daily, weekly and ...
3
votes
2answers
537 views

Best practice refactor n-tier into vertical slices architecture

What work path do there exist to identify reasonable vertical slices of a classic n-tier platform code base and infrastructure (enterprise size)? Regardles of refactor or a new solution I think there ...
3
votes
1answer
157 views

When to fracture a web application design into multiple products

Have you had this problem? You are building a complex web application for a target market, and after a while you reach a point in complexity where you can't decide if you are building more than one ...
6
votes
7answers
424 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 ...
9
votes
3answers
368 views

I have to compromise: DRY, or Command-Query-Separation?

I was recently refactoring a method that was both a command and a query method. After separating it into a one command method and one query method, I found that there are now multiple places in the ...
1
vote
1answer
298 views

Refactoring the shipping application code to use DDD factories

I was trying to find examples for using DDD factories and I came across the shipping application from Eric Evans' book. However when I checked the BookingService the code to create a Cargo had this ...
14
votes
8answers
734 views

Quantifying the value of refactoring in commercial terms [duplicate]

Here is the classic scenario; Dev team build a prototype. Business mgmt like it and put it into production. Dev team now have to continue to deliver new features whilst at the same time pay the ...
4
votes
2answers
166 views

How do you create documentation when there is none? [duplicate]

I have recently inherited a large, legacy system with a complex codebase that has a lack of documentation. I'm the sole internal developer embedded with the core users, taking some responsibility from ...
1
vote
1answer
75 views

A better approach to refactor code when doing A/B Testing

I'm asked to refactor my component code to support A/B Testing. What is the better approach: 1) Pass a boolean value to the methods and check for that flag inside the method body? method(flag ...
0
votes
3answers
1k views

What is good practice when inheriting static classes isn't possible/allowed

I am developing a project in C# and due to a design decision it is not possible to have a static class inherit another static class. But I have, in my opinion, a case where this would make sense. I ...
1
vote
5answers
349 views

Is it sometimes reasonable to cut corners and expect to re-write software in a couple of years? [duplicate]

I work for an organization with one developer (me) and one DBA. When I started, the previous developer had developed applications that had bad architectural practices and it was getting and more time ...
24
votes
10answers
12k views

How many lines per class is too many in Java? [closed]

In your experience, what is a useful rule of thumb for how many lines of code are too many for one class in Java? To be clear, I know that number of lines is not even close to the real standard to ...
2
votes
2answers
342 views

Should I split a Python class with many methods into multiple classes?

I have a class that will end up having more than ~30 methods. They all make sense to be part of the same class because they require access to the same data. However, does it make any sense to split ...
2
votes
3answers
198 views

Refactor working code for reuse or duplicate?

I have always avoided duplicating code regardless of the circumstance. For example, if I have a working piece of functionality that needs to be re-used by different entities, I always refactor to ...
59
votes
7answers
4k 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 ...