refactoring

How to refactor: split a class into two which communicate via an interface

I am just embarking on my first large-scale refactor, and need to split an (unfortunately large) class into two, which then communicate only via an interface. (My Presenter has turned out to be a Controller, and needs to split GUI logic from App logic). Using C# in VisualStudio 2008 and Resharper, what is the easiest way to achieve this?...

Telling bugs and features apart?

Have you ever been in the situation when looking at the code you couldn’t tell if something is a bug or poorly implemented feature? Or you simply didn’t dare to fix something that looked like a definite bug to you, but were not sure if anyone already relies on the functionality behaving in a certain way? What are your best heuristics ...

Explaining refactoring

Question My question is how can you teach the methods and importance of tidying-up and refactoring code? Background I was recently working on a code review for a colleague. They had made some modifications to a long-gone colleagues work. During the new changes, my colleague had tried to refactor items but gave up as soon as they hit a...

Need help making Jython (dom4j) script more graceful :)

Hi All, I have started using Jython as it seems to be a excellent language, and has proved to be so far. I am using dom4j to manipulate and retrieve data from the DOM of a bunch of HTML files I have on disk. I have wrote the below script to check threw the DOM using Xpath for H1 tags and grab text, if a H1 tag is not present in the DO...

Is it possible use or require a Perl script without executing its statements?

I need to add unit testing to some old scripts, the scripts are all basically in the following form: #!/usr/bin/perl # Main code foo(); bar(); # subs sub foo { } sub bar { } If I try to 'require' this code in a unit test, the main section of the code will run, where as I want to be able to just test "foo" in isolation. Is there a...

Eclipse: Relocating a git repo from project to workspace

I've been working on an Eclipse plug-in project for a while now, and I've run into a situation where I need to split the project up to seperate the test cases from the plug-in package. I'm using git as version control. To describe this simply, I'm versioning the old project like this: workspace/ | +-- myplugin/ | ...

Can this be refactored into nicey nice LINQ?

I have an IList of type Breadcrumb which is just a lightweight class that has NavigationTitle, NavigationUrl and IsCurrent properties. It is cached on the webserver. I have a method that builds out the current breadcrumb trail up until the first Breadcrumb that has IsCurrent set to true... using the code below. Its very ugly and definite...

SQL Server 2005: Wrapping Tables by Views - Pros and Cons

Background I am working on a legacy small-business automation system (inventory, sales, procurement, etc.) that has a single database hosted by SQL Server 2005 and a bunch of client applications. The main client (used by all users) is an MS Access 2003 application (ADP), and other clients include various VB/VBA applications like Excel a...

Refactoring "to hit" values for a game

I'm making a game and one of the methods calculates a character's base hit numbers based on skill values. The method currently calculates each value individually, since each skill can be used at short, medium, and long range. I originally thought I could combine the skills into a tuple and iterate over it, dynamically creating each hit ...

How could I improve this code ( C++ )

Hello ! I want your suggestion on the following pseudo-code . Please suggest how could I improve it,whether or not I could use some design patterns . // i'm receiving a string containing : id operation arguments data = read(socket); tokens = tokenize(data," "); // tokenize the string based on spaces if(tokens[0] == "A") { if(to...

Coming up with time/staff required estimates for converting a desktop app into a client-server app

My boss is bidding on a project to convert a desktop application into one that runs online as a client-server application. The original app has a little more than a quarter of a million lines of C++ (MFC) code that's not cleanly divided between engine and front-end. I need to come up with estimates of how long it will take and how many ...

How to convince my boss to do refactoring?

Hi All, We (developers) think we should do large grand refactoring in our project, because: With long time (more than 1 year) bug fixing too much hard code/hard logic been involved. Pickup one piece of code, nobody in this big team can confidentially tell you what will happen if you change that, because code are sticked together. We a...

Refactoring and concurrent development branches

You have several maintenance branches for existing releases of your software. Some developers are making direct changes in the maintenance branches, and merging periodically into the trunk. Now comes an extensive refactoring in the trunk codeline, scheduled for an upcoming major release. But this makes the maintenance branches fundamenta...

Best refactoring for the dreaded While (True) loop

If, like me, you shiver at the site of a While (True) loop, then you too must have thought long and hard about the best way to refactor it away. I've seen several different implementations, none really better than any other, such as the timer & delegate combination. So what's the best way you've come up with or seen to refactor the dre...

Find unused code

I have to refactor a large C# Application, and i found a lot of functions that are never used in the app. Is there a tool that can check for unused code, so i can remove all the unused functions? ...

Removing repeated conditions using polymorphism and the Factory pattern

<?php /** * My codebase is littered with the same conditionals over and over * again. I'm trying to refactor using inheritance and the Factory * pattern and I've had some success but I'm now stuck. * * I'm stuck because I want to derive a new class from the one * returned by the Factory. But I can't do that, so I'm obviously * d...

Cost of Rewriting a PHP application to Rails or Django

I am wondering your thoughts on doing a complete software rewrite. We realized after not long after we completed our software app that the framework was not going to scale well over time. For the record the framework was decided well before I got to the project. We are soon facing the reality that we will have to rewrite the entire app i...

Are there C++ free and fast (maybe standalone) refactoring tools for Windows?

At the moment I am working in a pretty big project and I have been been asked to refactor some old code. Most of the refactoring is setting apart a big class into smaller components and functions. I've searched and seen some other questions related with the topic but I am not very happy with the proposed options. The problem with these ...

Refactoring static method / static field for Testing

I have the following legacy code: public class MyLegacyClass { private static final String jndiName = "java:comp/env/jdbc/LegacyDataSource" public static SomeLegacyClass doSomeLegacyStuff(SomeOtherLegacyClass legacyObj) { // do stuff using jndiName } } This class is working in a J2EE-Container. Now I would lik...

Refactor traceListener code so it can be unit tested

Hello, I have the following code: private static void WriteStartupInfo() { Settings settings = Settings.Default; TimeSpan interval = settings.CleanupInterval; TimeSpan span = settings.ExpiryTimeSpan; string url = settings.TeamFoundationServerUrl; StringBuilder sb = new StringBuilder(); ...