refactoring

How do you test/change untested and untestable code?

Lately I had to change some code on older systems where not all of the code has unit tests. Before making the changes I want to write tests, but each class created a lot of dependencies and other anti-patterns which made testing quite hard. Obviously, I wanted to refactor the code to make it easier to test, write the tests and then chang...

Visual Studio refactoring: Remove method

Is there any Visual Studio Add-In that can do the remove method refactoring? Suppose you have the following method: Result DoSomething(parameters) { return ComputeResult(parameters); } Or the variant where Result is void. The purpose of the refactoring is to replace all the calls to DoSomething with calls to ComputeResult...

find orphaned methods in codebase

I'm sure we've all seen it before...A code base that has been around for a year or two, and as features have been added and bugs fixed, we end up with pieces of code that aren't actually in use anymore. I'm wondering if there is a way (especially in VS.NET with or without a third-party tool) to search the codebase and show me which meth...

Refactoring away labeled loops.

After I was convinced that labeled breaks/continues are a total "nono" over here, I need help to remove the label out of my code. I have a square matrix and a vector that has the same length. The vector has already some values in it an depending on the values in the matrix the vector is changed in the loop. I hope, the code-fragment is...

Good refactoring support for C++

The Visual Studio refactoring support for C# is quite good nowadays (though not half as good as some Java IDE's I've seen already) but I'm really missing C++ support. I have seen Refactor! and am currently trying it out, but maybe one of you guys know a better tool or plugin? I've been working with Visual Assist X now for a week or tw...

Tools for PHP code refactoring

Are there any tools which support refactoring PHP code (renaming variables, extracting methods, finding method references, ...)? Thank you. ...

Refactoring for Testability on an existing system

I've joined a team that works on a product. This product has been around for ~5 years or so, and uses ASP.NET WebForms. Its original architecture has faded over time, and things have become relatively disorganized throughout the solution. It's by no means terrible, but definitely can use some work; you all know what I mean. I've been pe...

Any ReSharper equivalent for Xcode?

I'm a complete Xcode/Objective-C/Cocoa newbie but I'm learning fast and really starting to enjoy getting to grips with a new language, platform and paradigm. One thing is though, having been using Visual Studio with R# for so long I've kind of been spoiled with the coding tools such as refactorings and completion etc and as far as I can...

When do you know it's time to rewrite an application

This is humbling, but probably something most can relate to. I am currently adding functionality to a PHP application I wrote for a client 2 years ago. In the interest of full disclosure, this was the first "real" application I ever built from the ground up, in the sense that I actually met with clients to determine and write a spec. ...

Cleanest Way to Find a Match In a List

What is the best way to find something in a list? I know LINQ has some nice tricks, but let's also get suggestions for C# 2.0. Lets get the best refactorings for this common code pattern. Currently I use code like this: // mObjList is a List<MyObject> MyObject match = null; foreach (MyObject mo in mObjList) { if (Criteria(mo)) ...

Best practices for refactoring classic ASP?

I've got to do some significant development in a large, old, spaghetti-ridden ASP system. I've been away from ASP for a long time, focusing my energies on Rails development. One basic step I've taken is to refactor pages into subs and functions with meaningful names, so that at least it's easy to understand @ the top of the file what's ...

What kind of database refactoring tools are there?

I am looking for something to integrate to my CI workflow. I've heard of dbdeploy (http://dbdeploy.com/) but I'm looking for something else. The reason I don't like dbdeploy is I don't want to install java on my server. I would prefer of course that the solution doesn't involve stringing some shell scripts together. ...

How can I merge my files when the folder structure has changed using Borland StarTeam?

I'm in the process of refactoring some code which includes moving folders around, and I would like to regularly merge to keep things current. What is the best way to merge after I've moved folders around in my working copy? ...

What refactoring tools do you use for Python ?

I have a bunch of classes I want to rename. Some of them have names that are small and that name is reused in other class names, where I don't want that name changed. Most of this lives in Python code, but we also have some XML code that references class names. Simple search and replace only gets me so far. In my case, I want to rena...

Rewrite or repair?

I'm sure you have all been there, you take on a project where there is a creaky old code base which is barely fit for purpose and you have to make the decision to either re-write it from scratch or repair what already exists. Conventional wisdom tends to suggest that you should never attempt a re-write from scratch as the risk of fail...

How can I convince skeptical management and colleagues to allow refactoring of awful code?

At work I have found it very difficult to 'sell' the idea of refactoring to management and senior colleagues. This is despite us having inherited a truly awful codebase (we all thought it was awful including them) from a programmer who really shouldn't be in the profession. I recommended over and over that we refactor and it simply didn'...

How many constructor arguments is too many?

Let's say you have a class called Customer, which contains the following fields: UserName Email First Name Last Name Let's also say that according to your business logic, all Customer objects must have these four properties defined. Now, we can do this pretty easily by forcing the constructor to specify each of these properties. Bu...

Which is a better refactoring tool for a beginner (something easy to learn & use)?

Resharper, RefactorPro, etc? ...

Where to find resources on Refactoring?

Refactoring is the process of improving the existing system design without changing its behavior. Besides Martin Fowler's seminal book "Refactoring - Improving the design of existing code" and Joshua Kerievsky's book "Refactoring to Patterns", are there any good resources on refactoring? ...

Tracking Refactorings in a Bug Database

Let's say you work someplace where every change to source code must be associated with a bug-report or feature-request, and there is no way to get that policy reformed. In such an environment, what is the best way to deal with code refactorings (that is, changes that improve the code but do not fix a bug or add a feature)? Write up a ...