Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.
24
votes
9answers
2k 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 ...
0
votes
2answers
199 views
Eliminate duplicate code in nested IFs without creating a function
Let's say we have two ifs that depend on each other:
if var exists {
if var is array {
//Do stuff with var
} else {
//Resolve the problem
}
} else {
//Resolve the ...
0
votes
5answers
451 views
Fixing bugs in other peoples code [duplicate]
I'm working with another programmer and we are always having issues with refactoring or changing each others code. Recently I had to fix a bug, but I pushed the changes before notifying him. He was ...
1
vote
1answer
234 views
I made improvements to free code I found online and notified the author. Was this the right thing to do? [closed]
I recently used a library from http://www.braemoor.co.uk/software/index.shtml (the EU VAT No validation library at http://www.braemoor.co.uk/software/vat.shtml) in a project at work. It mentions as ...
1
vote
3answers
104 views
Can I refactor “safely” without specs? [duplicate]
I have inherited a legacy web application many years which:
Does not make use of Object Oriented principles, even though the language would permit it
Has no unit tests, nor any sort of test suite, ...
0
votes
0answers
39 views
Refactoring a Single Rails Model with large methods & long join queries trying to do everything
I have a working Ruby on Rails Model that I suspect is inefficient, hard to maintain, and full of unnecessary SQL join queries. I want to optimize and refactor this Model (Quiz.rb) to comply with ...
2
votes
2answers
129 views
When does extracting methods from code stop to make sense? [duplicate]
I am currently studying the refactoring methods defined by Marting Fowler (http://refactoring.com/catalog/).
He states a tip for replacing chunks of code by a single method that does that job. So ...
6
votes
1answer
223 views
Suggested method for extracting a standalone C library from an existing R package?
My group has been developing an R package to simulate plant growth (see GitHub repository). The R package uses .Call to interface with C.
We have decided that it would be worthwhile to create a ...
0
votes
0answers
34 views
Rewriting/decoupling important service of the Django website in Erlang
We have application written entirely in Django, which consist of three separate components. Admin, Service for generating invoices + API and UI for users. Problem is, that they are very tightly ...
1
vote
2answers
203 views
Retrying a statement or call in a catch block - code smell or anti-pattern?
I'm wondering how better to perform this operation for a large amount of files. The bit I'd like some thoughts on whether this copy/paste is acceptable enough of a tradeoff.
try to write a file
if ...
2
votes
2answers
259 views
Reduce number of if statements through design pattern
I had a loop through object Process, each process instance can be of a different type, derived from Process base class (e.g.: Process1, Process2,...). Each derived type of Process has different ...
38
votes
12answers
3k views
Reconciling the Boy Scout Rule and Opportunistic Refactoring with code reviews
I am a great believer in the Boy Scout Rule:
Always check a module in cleaner than when you checked it out." No
matter who the original author was, what if we always made some
effort, no ...
68
votes
6answers
5k views
Fixing a spelling mistake in a method name
One of the methods that I commonly use in our codebase is misspelled (and it predated me).
This really irritates me not simply because it is mispelled but more importantly it makes me ALWAYS get the ...
1
vote
1answer
198 views
Advice on refactoring PHP Project
I have a small SAS ERP that was written some years ago using PHP.
At that time, it didn't use any framework, but the code isn't a mess.
Nowadays, the project grows and I’m now working with 3 more ...
9
votes
3answers
315 views
Continuing to code on large projects
I am a hobbyist programmer, and I've started many medium - sized projects to work on just by myself. These include games, a raytracer, physics simulations etc.
By the time these projects get to a ...
5
votes
2answers
223 views
How should I refactor switch statements like this (Switching on type) to be more OO?
I'm seeing some code like this in our code base, and want to refactor it:
(Typescript psuedocode follows):
class EntityManager{
private findEntityForServerObject(entityType:string, ...
0
votes
2answers
143 views
Follow the deadlines vs Do it right [duplicate]
I have been given a huge task of migrating few functionalities from jQuery to AngularJS. I have been pretty good at Angular by now. But I want to dive deep and create futuristic, sound architecture. ...
1
vote
3answers
131 views
Use unnamed object to invoke method or not?
If I have a class with only only public method. When I use this class, is it good to use unnamed object to invoke its method?
normal:
TaxFileParser tax_parser(tax_file_name);
auto content = ...
8
votes
1answer
397 views
Refactoring a 1500 LOC method that only builds the graphical UI [closed]
I'm currently scratching my head over how to refactor a method that basically only builds the UI.
The method is more than 1500 lines of code (LOC) long - and counting. It has grown, there was no plan ...
0
votes
1answer
96 views
Can JSP Expression Language provide type safety like scriptlets in Eclipse IDE?
Almost everywhere you can read that you should use EL instead of scriptles in JSP. And I agree that you should not use any JAVA code in JSP except for calling getter methods on model objects. This is ...
1
vote
1answer
91 views
How to manage a winforms application installed in many PCs connected to a single sql database?
I have a winforms application that connects to a single sql server 2012 database and is executed in many PCs of a company.
I'm having several problems with some transactions inside the application, ...
4
votes
2answers
146 views
Refactoring a live system that is tightly coupled with improper data models and business logic in the front-end
Scenario
This was a project that I once had to maintain. After reading Working Effectively with Legacy Code, I started to think how I would refactor this system in a live environment, if I had to ...
2
votes
5answers
426 views
DRY code, DRY tests?
At some point I had to create some class "Class1" and that class needs a method "method". So I have the following:
Class1MethodTest: A total of N tests that check the behavior of Class1.method
Class1 ...
2
votes
2answers
120 views
According to software engineering which method are too long? [closed]
I was just working with a method of about 70 lines of code developed by others. It uses a very nice pattern structure, stuff like IOC container, but I wonder.. The method is too long?
Is it a so long ...
0
votes
7answers
780 views
Is there any performance benefit in checking the item count prior to executing a foreach loop?
I saw this in code and was wondering if there is any performance benefit to checking the item count prior to looping:
if (SqlParams.Count > 0)
foreach (var prm in SqlParams)
...
2
votes
4answers
226 views
Should refactoring be the exception or the rule? [closed]
I had a discussion with a co-worker yesterday about design philosophy. The other coder is more experienced then me, and I fully admit that he is likely much better at properly automating his testing, ...
2
votes
2answers
401 views
What is “the refactoring method” for understanding code wrote by someone else?
I wrote code, but I myself many times don't even understand the code i wrote. I heard people using "refactoring method" to help them to understand others' code.
I just knew a very little about ...
4
votes
4answers
265 views
How to avoid excessive method overloading?
We have quite a lot of places in the source code of our application , where one class has many methods with same names and different parameters. Those methods always have all the parameters of a ...
0
votes
1answer
65 views
testing: which code layers should I aim to test?
Say I have this code:
Design
{
public function load()
{
$this->loadProduct();
$this->loadService();
...
}
public function loadProduct()
{
...
4
votes
3answers
214 views
How to avoid programmers duplicating code [duplicate]
While I know in a perfect world where a greenfield application was scoped out from day one with great BRD's and a competent development lead constantly reviewed code by their underlings to avoid this, ...
0
votes
1answer
156 views
Is there a Pattern or a Refactoring Method to pull data-loading out of existing Class
I am refactoring legacy codebase. Part of it is a loadProduct() function inside a larger "everything" class. loadProduct() loads data from a database. I want to move this loading-data part out of ...
0
votes
0answers
34 views
Best practices for introducing testing to a large, stable, legacy Java application? [duplicate]
I'm working with a stable, but large legacy java application that is over 12 years old, maybe older.
Although the code has been upgraded to java 6, it's lacks the features above java 1.4 for the most ...
8
votes
5answers
706 views
Why write tests for code that I will refactor?
I am refactoring a huge legacy code class. Refactoring (I presume) advocates this:
write tests for the legacy class
refactor the heck out of the class
Problem: once I refactor the class, my ...
0
votes
1answer
54 views
Inverse of Extract Interface refactoring
I'm working with a Java project that has several interfaces, many of which have only one implementation. (See related question)
For a given revision of the software, one could think this acceptable ...
1
vote
3answers
150 views
How do I evaluate if an Orchestration is the appropriate design pattern for a given problem?
Say that you're doing a code review, and you find yourself faced with an orchestration pattern:
class OrchestrationClass {
private Configuration _configuration;
private DataStore1 _dataStore1;
...
5
votes
2answers
117 views
How to keep track of links pointing to existing web applications in an Intranet?
At my new place of employment we have a Intranet solution containing multiple web applications hosted in IIS. Outside of the development department other departments either source or create other ...
14
votes
7answers
1k views
Should I refactor large functions that mostly consist of one regex? [closed]
I just wrote a function that spans approximately 100 lines. Hearing that, you are probably tempted to tell me about single responsibilities and urge me to refactor. This is my gut instinct as well, ...
3
votes
2answers
136 views
How to handle not-quite-legacy code? [duplicate]
This is a frequently asked topic... And I have read through many posts, articles and am about to read the book Working Effectively with Legacy Code, but before that and mainly because it will take ...
0
votes
1answer
123 views
Am I doing it wrong with Hibernate DAO layer? i.e. Feature Bloat
For quick prototyping I have been actively using Hibernate. Recently I came back to an old project and I wondered why I had a lot of DAOs with what I suspect is commonly named feature bloat. E.g.
I ...
0
votes
0answers
62 views
On the process of replacing an internal framework by a public one [duplicate]
I am working on several applications which depends on a framework which was developed by a prior engineer in the company. The framework was mainly developed and maintained in the early 2000s, and ...
3
votes
1answer
233 views
Object Calisthenics - reducing to two attributes
I'm refactoring an expense tracker system using Object Calisthenics. I'm able to bring my Class down to five attributes. How do I go forward from here?
This is my class right now.
public class ...
1
vote
2answers
137 views
Code Duplication in Multi-Module Project
I've about seven modules arranged like so:
Service
Processing
Common
Account
Email
Scheduling
I try to make it my policy to restrict code to the module that actually uses it. Code that is shared ...
5
votes
3answers
137 views
Engineering a better solution, coming from existing codebase [duplicate]
The Code
I have high-business-value daily-used-by-customer software that is written in PHP and spans approximately 600K lines of code.
Customer for a long time needs, wants, and demands new features ...
2
votes
3answers
169 views
When subclassing is it better to “Copy Paste, then Refactor”, or “Refactor, then Implement”
I currently have a class Foo,
i've decided I need a second type of Foo where I want to test out a significantly different implementation. It will no doubt share some functionality with Foo so I'll ...
62
votes
10answers
4k views
Does it make sense to write tests for legacy code when there is no time for a complete refactoring?
I usually try to follow the advice of the book Working Effectively with Legacy Code. I break dependencies, move parts of the code to @VisibleForTesting public static methods and to new classes to make ...
1
vote
2answers
217 views
Query Language for Java Code Analysis
I want to write a refactoring tool for the Java programming language.
For this reason I need to do structural queries against the abstract syntax tree. Given this AST how do I get answers to the ...
17
votes
4answers
1k views
How to convince/prove my manager that a rewriting is needed rather than a refactoring [duplicate]
My manager wants me to refactor a gigantic amount of terribly-coupled, macroed, full of private namespace methods, hierarchy-perverted (even 10+ levels of inheritance) code which hasn't been (indeed) ...
1
vote
3answers
111 views
Refactoring - Utility classes behavior under a common interface
I was suggested to put my question here, so I'm doing so ;)
I need a common interface which represents some specific behavior:
public interface Contract(){
public void methodA();
public void ...
3
votes
3answers
123 views
Can removing unnecessary file from a repo be considered part of refactoring?
We're using Git as our DVCS and we're about to start to do a clean up (never done before in this team) of files that are not necessary (not part of the sources) from our products.
This is done in two ...
5
votes
5answers
612 views
Martin Fowler's Refactoring book: switch statement is using other object's data, why is that bad ? A deeper explanation is sought for.
In the code sample below the Rental object is using Movie's fields to do a switch statement. Martin says : this is a bad idea but he does not give any deeper explanation as to why ?
Of course, you ...