Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.
6
votes
5answers
329 views
Is it a bad practice to modify code strictly for testing purposes
I have an ongoing discussion with a programmer colleague of mine about the question whether it is a good or bad practice to modify a working piece of code only to make it testable (via unit tests for ...
-3
votes
1answer
62 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
74 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 ...
4
votes
0answers
242 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
196 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
92 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
439 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 ...
10
votes
2answers
397 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
124 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
2k 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
233 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
344 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
59 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
458 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
115 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 ...
2
votes
3answers
148 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
344 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
427 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
96 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
180 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
473 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
190 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
270 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
358 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
172 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
199 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
275 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
273 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
472 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
246 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
444 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
171 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
187 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
215 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
406 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
795 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
226 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 ...
-1
votes
5answers
271 views
What do you do to overcome the need to make code perfect? [closed]
I'm sure I'm not the only one in this situation and I wanted to see what you guys do about this on day-to-day basis. Sorry if this comes off a bit ranty.
As a company founder and the main tech guy, I ...
1
vote
1answer
154 views
How to avoid huge functions with made up of enums and if-else or switch case when dealing with server response in iOS?
in my application,
I have a request type associated with variety of API calls I make to the REST server.
when the response from server comes in the same delegate method for web engine's response,
I ...
0
votes
1answer
174 views
How To Explain Need to Refactor Code to Non-Developer Boss [duplicate]
Possible Duplicate:
How do you explain refactoring to a non-technical person?
How to justify code refactoring time?
My supervisor is the CTO of the company that I work at, he is the jack ...
7
votes
3answers
354 views
is this javascript property defaulting pattern a code smell?
In some javascript code I'm working on refactoring I've handled cases where I wanted to default an object property to true without having to go through the code-base and add the property to every ...
16
votes
5answers
986 views
How do I prevent unknowningly duplicating code?
I work on a rather large code base. Hundreds of classes, tons of different files, lots of functionality, takes more than 15 minutes to pull down a fresh copy, etc.
A big problem with such a large ...
8
votes
2answers
224 views
Refactoring several huge C++ classes / methods. How to start? [duplicate]
Possible Duplicate:
I’ve inherited 200K lines of spaghetti code — what now?
I'm dealing with legacy code. It contains some BIG classes (line count 8000+) and some BIG methods (line count ...
9
votes
1answer
182 views
Looking for the better way to combine deep architecture refactoring with feature based development
Problem statement:
Given:
TFS as Source Control
Heavy desktop client application with tons of legacy code with bad or
almost absent architecture design.
Clients constantly requiring new features ...
1
vote
1answer
108 views
Is it justified to use project-wide unique function and variable names to help future refactoring?
Refactoring tools (like ReSharper) often can't be sure whether to rename a given identifier when, for example refactoring a JavaScript function. I guess this is a consequence of JavaScript's dynamic ...
7
votes
4answers
374 views
Would you refactor this and if so, would you charge your client?
I am working on a freelance job at home. The client wants me to write some new functionality for his CMS, but it is taking me a lot of time to figure out what the code is doing, because it is written ...
0
votes
2answers
210 views
Question on refactoring and code design
Suppose, I have a class with a constant static final field. Then I want in certain situations that field to be different. It still can be final, because it should be initialized in constructor. My ...
2
votes
4answers
293 views
Can notes/to-dos in code comments sent to code-reviews result in an effective refactoring process?
I want to start/improve a culture of collective code ownership at my company but at a geographically distributed level... I'd say there is some current collective code-ownership mentality, but only at ...
21
votes
5answers
1k views
What is the politically correct way of refactoring other's code?
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 ...


