Tagged Questions
Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.
-3
votes
4answers
188 views
Loop unrolling as refactoring technique [on hold]
Why I can not find information in Internet about loop unrolling as refactoring technique? The only tool I found is photran for Fortran.
Where can I find more info about it? Techniques aka Fowler, ...
-1
votes
1answer
78 views
Refactor if statements that conditionally create an object [closed]
(first post here, Hello World!)
I've got a series of if's (some nested) that decide the properties of my $object.
Now I'm wondering if this can be refactored since this doesn't look clean to me.
...
5
votes
4answers
192 views
Using different patterns for similar features
I'm the sole developer on a project that, like for any software project, may be taken by somebody else in the future.
Let's say I used the pattern X to implement feature A. After developing and ...
0
votes
2answers
180 views
Is “Introduce Parameter Object” actually a good pattern?
I have a situation where I want to call a function which requires a number of parameters. This function is not called directly, it is called indirectly and the parameters are delegated several times. ...
1
vote
1answer
100 views
Refactoring Password Validation Utility
Given a password, I am trying to validate if it passes all validation rules such as
Be at least 6 characters long
Contain at least one letter (a-z or A-Z)
Contain at least one number (0-9)
...
3
votes
2answers
264 views
+50
Pure POJO refactoring Active Record Pattern using Repository Pattern, no ORM or DI frameworks for pedagogical reasons
I taught a course years ago, and then I used some JDBC exercises using what I now know is the Active Record Pattern.
I would like to modernize the exercise by changing the Active Record Pattern so ...
1
vote
1answer
242 views
What's a good approach for refactoring code that starts looking like spaghetti?
Synopsis:
I am working on a level editor for a game written using Unity, the game is actually a new engine for an old game. This is a +20 years old game and its data structures are by today standards,...
7
votes
1answer
110 views
Replacing Dynamic SQL w/ a Filtering Pipeline?
As part of a work assignment I've long dealt with a giant, dynamic SQL-creating stored procedure that's used for retrieving a bunch of inventory items. This stored procedure accepts a ton of ...
3
votes
1answer
57 views
Modifying the tests and refactoring duplicate code in test driven development
I am trying test driven development for the first time (test first development, actually). I wrote down my specifications, then alternated writing tests, then code, writing the code to pass the latest ...
1
vote
2answers
159 views
What to do, if I need non generic class use generic inside, but don't want pass down type arguments
Let's assume we have something like that:
class Page{
Header header;
Body body;
Footer<TFooterModel> footer; //TFooterModel is a type of content (subcontrol in some sense) that ...
2
votes
1answer
55 views
Detecting massive classes that are good candidates for refactoring
Does anyone know of any tool that would help find classes that are taking on too much responsibility?
E.g. By visualizing a file's size compared to the other files in the code base, it can be easy to ...
1
vote
2answers
92 views
Continuous Integration and a Massive Refactor
I'm currently re-factoring a part of our application at work. I'm normalising a data structure from a flat list of fields to a parent/child relationship. This has an impact on all layers in the ...
0
votes
3answers
246 views
Is it bad practice to ignore some parameters while implementing a method of a interface?
Should an interface method implemented by a class always use all parameters? By interface I do not necessarily mean actual interfaces, these could be other (abstract) classes which are extended, too.
...
1
vote
2answers
60 views
Refactoring to an inheritance hierarchy early on
I am building a management tool for recipes. Recipes have a bunch of data, including very generic stuff like an ID, tags, ratings and trivia. I currently only manage recipes, but i want to add support ...
0
votes
1answer
59 views
Recommended strategy for changing javascript UI table library?
tl;dr - On an existing angularjs grid library, am moving to another.
Is it better to wipe out as much code as possible and in a sense code from scratch to the same featureset, or work around what's ...
0
votes
1answer
34 views
Separate context-dependent information from the core logic code
Say, I have a code file where all the core logic is located. In addition, I have some custom logic that is defined by some flags, like
if (a && b && c) {}
if (!e && f) {}
...
0
votes
0answers
43 views
Should I split function reference into a class reference and method reference?
We have code like ['Index::Show::AjaxPost', ...] which references a function AjaxPost in Index::Show module.
I was ordained to refactor it in object oriented manner.
Should I split it into [['Index::...
2
votes
2answers
104 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,...
5
votes
2answers
102 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);
...
2
votes
0answers
93 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 ...
165
votes
20answers
21k views
A large part of my code has a major design flaw. Finish it off or fix it now?
I am a high school student working on a C# project with a friend of mine with about the same skill level as me. So far, we have written roughly 3,000 lines of code and 250 lines of test code in a span ...
2
votes
2answers
87 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 ...
20
votes
6answers
2k 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 ...
53
votes
9answers
6k 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
3answers
200 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 ...
2
votes
2answers
33 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 ...
8
votes
4answers
247 views
Should You Improve Code Quality Whilst Working on a Feature Branch
I really like this article about leaving the code/camp site in a nicer state than you found it - it seems like a practical approach in the real world to keep on top of code cleanliness.
I also ...
0
votes
1answer
44 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
2answers
79 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 ...
2
votes
2answers
70 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 ...
0
votes
2answers
85 views
Proper design for function doing one job but involving many little tasks
I have a class in Python that its only responsibility is receive text, a font path, max font size and min font size and print the text on an image if it fits.
I have a function named word_wrap() and ...
3
votes
2answers
243 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
0answers
12 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 ...
4
votes
1answer
134 views
Define “Refactoring”
Everyone has heard this term thrown around, and most people, I would imagine, have a conceptual idea of the meaning. I, myself, am in that latter group. However, I feel that the definition Google/...
5
votes
3answers
275 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 ...
1
vote
3answers
90 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 ...
2
votes
2answers
160 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
1answer
409 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
1answer
75 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
1answer
70 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
1answer
100 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 ...
1
vote
4answers
141 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
1answer
196 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
2answers
74 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 ...
1
vote
2answers
129 views
What are polymorphic messages? [duplicate]
I am reading Martin Fowler's 'Refactoring: Improving the Design of Existing Code'. I have not understood a section of the second chapter where Kent Beck describes the pros of indirection.
One of the ...
6
votes
2answers
376 views
How does breaking up a big method into smaller methods improve unit testability when the methods are all private?
I'm presently reading Building Maintainable Software by Joost Visser and some of the maintenance guidelines they recommend include: A) each unit/method should be short (less than 15 lines per method) ...
16
votes
8answers
3k 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 ...
24
votes
6answers
3k 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 ...
1
vote
1answer
75 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
3answers
166 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 ...