Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.
0
votes
1answer
54 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
0answers
29 views
Refactor LINQ & XML code [migrated]
I have some duplicate code using LINQ & XML. I'm sure there is a way to refactor it, but I'm not sure how to go about doing it. Would someone help, please?
var fileInfo = ...
3
votes
2answers
65 views
How to refactor to cleaner version of maintaing states of the widget
Backstory
I inherited a bunch of code that I'd like to refactor. It is a UI application written in javascript.
Current state:
We have main application which consist of several UI components. And ...
0
votes
0answers
23 views
What would be the best way to refactor/rewrite a large base of plsql packages?
Let's suppose I have a large set of Oracle plsql packages and functions written in a period of 10+ years.
They are really hard to debug and maintain, and as the application grows we find it harder ...
0
votes
1answer
93 views
Refactoring classes with ref to themselves
How can I refactor this code?
class Node
{
public Node Parent { get; set; }
}
class AVLNode
{
public AVLNode Parent { get; set; }
}
I tried to use inheritance, but then I have to use type ...
1
vote
1answer
113 views
Reducing repetitive DI code
I have a method which constructs dependencies using Unity. Currently, all of the calls do pretty much the same thing: Registers 2 repository object and 2 'App Part' objects. My issue is, there's a lot ...
0
votes
2answers
138 views
Similar references to themselves in two classes
How can I make 1 class (base, generic or something else) from these two classes?
class A
{
A Link { get; set; }
}
class B
{
B Link { get; set; }
}
UPD: This is what I have now:
class BSTree
{
...
0
votes
2answers
165 views
How do I explain the value of refactoring to stakeholders? [duplicate]
How do I convince project managers, product owners, business analysts, clients and various other stakeholders that refactoring is a worthwhile and productive part of the development process?
As ...
4
votes
3answers
149 views
Is it okay to call a model method in my view?
In the interest of keeping my Controller's skinny, I put a headline method in a Model.
# My Model
class Property
def headline
"#{name} | #{address}"
end
end
(Then, Property Controller for ...
3
votes
2answers
235 views
Refactoring c++
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 ...
1
vote
4answers
156 views
How Much Of A (Broken) Legacy Framework To Keep [duplicate]
I've inherited a hosted system (system "A") which can be used to manage products, inventory, and orders, and can send those products to various third-parties.
Quite simply, system "A" doesn't work. ...
36
votes
9answers
4k 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 ...
-3
votes
1answer
67 views
Refactoring methods with the same behavior [closed]
Imagine you have 2 methods :
GetConsolidation([...]);
GetReportOfConsolidation([...]);
These 2 methods use the same "behavior" (some local variables assigned with data) like :
var data = ...
0
votes
1answer
118 views
Introducing Fowler's Table Data Gateway to refactor poorly designed systems
I am developing an application, which currently has about 150,000 lines of code. The previous developer didn't really use any discipline when writing code. Application is in production but is ...
3
votes
1answer
302 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 ...
6
votes
1answer
201 views
Reasoning to wait until third time in the Rule of Three?
I just came across the article "Rule of Three" in wikipedia
Rule of three is a code refactoring rule of thumb to decide when a
replicated piece of code should be replaced by a new procedure. It
...
1
vote
2answers
106 views
How to handle product rebranding in code in a short time frame
We've all been there - a product feature is called "gold", and then a week before launch they decide it is to be called "platinum". Luckily, you had some nous about you so the UI code is easy to ...
11
votes
1answer
451 views
Are there any statistics on how often code is read?
I have often come across claims that source code is read much more than it is written and just wanted to do a little calculation like:
If you write a line that takes me 5 minutes longer to read ...
11
votes
2answers
442 views
I should have used a factory method instead of a constructor. Can I change that and still be backwards-compatible?
The problem
Let's say I have a class called DataSource which provides a ReadData method (and maybe others, but let's keep things simple) to read data from an .mdb file:
var source = new ...
2
votes
2answers
127 views
Starting a recurring project from scratch [duplicate]
We have a project that keeps recurring. The client expects us to run a website twice a year and this is happened for the last year and a half. I took the last working copy and based our latest website ...
42
votes
12answers
3k views
Coding style (do more, then simplify) [duplicate]
I'm a CS student and I have been coding for a few months shy of a year now, and I seem to have developed what I think may be a "bad" habit and I'm wondering if anyone does the same (or whether it's a ...
1
vote
2answers
245 views
Prevent code from getting mess [duplicate]
I am a student and a freelance programmer. These days I am developing a software in VB6 which has recently crossed 100KB of source code.
The main problem, I face is, many times I have to refactor my ...
6
votes
4answers
373 views
What would help when refactoring a large method to ensure that I don't break anything?
I'm currently refactoring a part of a large codebase with no unit tests whatsoever. I tried to refactor code the brute way, i.e. by trying to guess what the code is doing and what changes wouldn't ...
0
votes
1answer
63 views
How to 'convert' a Static Access style project to IoC/DI style?
Are there any best approaches for refactoring a programming project that has previously been written with the static reference anti-pattern (the majority of classes refer at some point to a static ...
3
votes
2answers
468 views
How many regression bugs from refactoring is too many.
Recent QA testing has found some regression bugs in our code. My team lead blames recent refactoring efforts for the regressions.
My team lead's stance is "refactor, but don't break too many things", ...
2
votes
1answer
117 views
Agile: When to re-factor and when to extend while accruing technical debt? [duplicate]
Consider the following scenario.
You currently have a feature set A you wish to extend to include feature set B. In the near feature there's a high possibility that you wish to extend this even ...
57
votes
7answers
3k 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
3answers
149 views
Evaluating the complete revision of other's software
I'm having some difficulty to evaluate the revision of a software: the software was paid by customer years ago, never used, and now the customer have noticed that it doesn't work as expected.
Now ...
5
votes
2answers
360 views
When is it inappropriate to make objects immutable?
I have a class which represents an entity object in our system (for sake of argument, a Customer object)
public class Customer()
{
private int id;
private String name;
... // 30+ fields
...
6
votes
4answers
451 views
Hating your own code - for good or bad, how do you deal with it? [closed]
Have you ever had this feeling that your code is bad, the whole project is a mess, and you just want to step off? On your daily job you can explain this feeling away with your coworkers, asshole boss, ...
1
vote
0answers
101 views
Refactoring expansive message architecture
I am currently working with a system that acts like a message bus. A message comes in to the service (WCF Windows Service hosted). The system then uses a service locator pattern to look up which ...
6
votes
3answers
183 views
Should a new class refactored out of an existing one have history pointing back to it's progenitor
If I split one class into two classes should both classes have history in source control tracing back to the original class that contained both; or should the new class be added as a new file without ...
40
votes
10answers
2k views
Is it a good idea to schedule regular time to clean up code? [closed]
I'm managing a small team of developers. Every so often we decide we're going to spend a day or two to clean up our code.
Would it be a good idea to schedule regular time, say 1 week every 2 months, ...
4
votes
2answers
494 views
How do I handle having so many SQL queries?
I have an MVC3 project that uses SQL Server.
I use data from the SQL database all the time and I often find that I'm reusing/duplicating some SQL queries. I thought I'd solve this problem by creating ...
4
votes
3answers
199 views
Using the mouse as a multi-tool creates heavy conditional logic for executing commands, how do I change this?
The feature is in many different types of editing programs where a mouse click may have completely different commands to execute (using the Command Pattern)
Currently I have an overarching ...
3
votes
7answers
302 views
Naming guard clauses that throw exceptions
I have a function evaluate() that parses a String for some variables and replaces them with their corresponding value:
public String evaluate() {
String result = templateText;
for ...
4
votes
2answers
410 views
Is it possible to avoid enormously big switch in that case? [duplicate]
I'm writing a simple chess-related code with intention to write it clearly (performance doesn't matter at all). And this method I have doesn't look clean to me at all:
public static Piece ...
5
votes
2answers
177 views
How to do unit tests on a method that takes the elapsed time into account?
I'm currently in the middle of refactoring an important method in a legacy-system. There were almost zero test until I've started working on it, and I've added quite a lot to ensure the correct work ...
4
votes
3answers
211 views
How should I go about “overhauling” a large legacy application? [duplicate]
Possible Duplicate:
I’ve inherited 200K lines of spaghetti code — what now?
For my next project, I've been tasked with "overhauling" a large legacy web application with many parts. It is a ...
4
votes
3answers
280 views
Renaming long named method in C# [closed]
I'm working on a project where exist one method with title
string ValidateNewPasswordExpireCurrentPasswordAndCreateNewPassword(...)
I'm sure the method name must be changed. But can't found good ...
0
votes
4answers
275 views
How to refactor such code? [closed]
The project is full of such code and the function is really long and hard to understand..
How to refactor?
int get_greate_structure(GreateStructure* st)
{
switch (st->type)
{
case 1:
...
7
votes
3answers
485 views
Cleaning Up Generated Code: Refactor or Map?
Context:
I recently had to deal with a class file generated by XSD.exe. It was 3500 lines long with ridiculously-verbose class / variable names (think ...
3
votes
2answers
259 views
How to remove duplicate exception block code
I have good number of Service and DAO classes which has the same set of 30 line exception code block which gets repeated and it shows up in Code Duplication report.
The approach which i can think of ...
0
votes
0answers
534 views
Is there an alternatives to Visual Studio's Visual Assist X plug-in for Mac? [closed]
Are there any text-editors, or plug-ins for text-editors that will implement a C++ function/method automatically for you? Then I wont have have to copy and paste re-type the method/function out every ...
2
votes
2answers
176 views
Overcoming circular reference
I am working on an asp.net MVC web application which contains several projects.
One is BusinessObjects, which contains business logic / processes.
Another is EmailGeneration which is used to send ...
2
votes
0answers
227 views
Tools for finding unused files in web application [closed]
Is there any tools to find unused js, css and image files in web application?
Something like Resharper for these files.
I've a web application developed by someone else; He has included a lot of js ...
0
votes
1answer
269 views
JavaScript refactoring tool [closed]
I'm on the process of refactoring a large JavaScript application, which has a lot of repeated functions with 2 or 3 different parameters, a lot of global variables used in several modules, etc.
Which ...
5
votes
8answers
416 views
Refactoring: Two big chunks within a function
I am designing an API which mostly involves refactoring the original code.
So Right now I have a method which has two big chunks which are seperated by an If-else condition, which in my opinion is ...
9
votes
7answers
802 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 ...
4
votes
3answers
235 views
How to refactor “nested” view classes to avoid deep method calls?
Lets say I'm displaying a bunch of data (model) using a View class for rendering. However, a lot of the data has sub-data (models) complicated enough to require separate rendering classes.
In my ...