refactoring

Starting a new job focused on brownfield application refactoring & Agile

I am starting a new job on Monday. The company has a home grown enterprise case management application written in ASP.NET/VB.NET. They are attempting to implement an Agile development process. They have gone so far as to get two people Scrum Master certified and hire an Agile coach. They are currently focused on 6-9 months of refactoring...

In C# (or any language) what is/are your favourite way of removing repetition?

I've just coded a 700 line class. Awful. I hang my head in shame. It's as opposite to DRY as a British summer. It's full of cut and paste with minor tweaks here and there. This makes it's a prime candidate for refactoring. Before I embark on this, I'd thought I'd ask when you have lots of repetition, what are the first refactoring op...

How to write a Rails mixin that spans across model, controller, and view.

In an effort to reduce code duplication in my little Rails app, I've been working on getting common code between my models into it's own separate module, so far so good. The model stuff is fairly easy, I just have to include the module at the beginning, e.g.: class Iso < Sale include Shared::TracksSerialNumberExtension include Shar...

Refactoring and Source Control: How To?

I am completely on board with the ideas behind TDD, Refactoring and Patterns however it does seem like there is a huge gaping whole in these ideas, mainly that they are great for dev teams of 1, but when you start refactoring code that 10 people are working on you start getting merge conflicts all over the place and most diff/merge softw...

Best Refactor to Handle Multiple jQuery Email Field Form Validation

What is the best way to refactor the attached code to accommodate multiple email addresses? The attached HTML/jQuery is complete and works for the first email address. I can setup the other two by copy/pasting and changing the code. But I would like to just refactor the existing code to handle multiple email address fields. <html> <hea...

How do you find your way around a new codebase

You don't always get to talk to the original author or authors of the code you maintain. Sometimes when I work on an existing project I feel like a special forces operative behind enemy lines trying to figure out the lay of the land without the use of a map. When you are in this situation how do you get the code under control? How do you...

Refactoring in Ruby

Are there any programs or IDEs that support refactoring for Ruby or RoR? ...

How do you justify Refactoring work to your penny-pinching boss?

You've just written a pile of code to deliver some important feature under pressure. You've cut a few corners, you've mashed some code into some over-bloated classes with names like SerialIndirectionShutoffManager.. You tell your boss you're going to need a week to clean this stuff up. "Clean what up?" "My code - its a pigsty!" "You...

Refactor Mercilessly or Build One To Throw Away?

Where a new system concept or new technology is used, one has to build a system to throw away, for even the best planning is not so omniscient as to get it right the first time. Hence plan to throw one away; you will, anyhow. -- Fred Brooks, The Mythical Man-Month [Emphasis mine] Build one to throw away. That's what they t...

Unit testing for C++ code - Tools and methodology

I'm working on a large c++ system that is has been in development for a few years now. As part of an effort to improve the quality of the existing code we engaged on a large long-term refactoring project. Do you know a good tool that can help me write unit tests in C++? Maybe something similar to Junit or Nunit? Can anyone give some go...

How to programmatically determine param name when constructing an ArgumentException?

When constructing an ArgumentException, a couple of the overloads take a string that is the invalid argument's parameter name. I figure it would be nice to not have to remember to update this ctor param whenever I change the method's param name. Is there a simple way to do this using reflection? Update: thanks to the 2 respondents so fa...

Can eclipse extract a second class in class file to its own file

I often refactor code first by creating an inner class inside the class I'm working on--When I'm done, I move the entire thing into a new class file. This makes refactoring code into the new class extremely easy because A) I'm only dealing with a single file, and B) I don't create new files until I have a pretty good idea of the name/na...

How to Refactor to Generics from Class that Inherits from CollectionBase?

I am working on an application that is about 250,000 lines of code. I'm currently the only developer working on this application that was originally built in .NET 1.1. Pervasive throughout is a class that inherits from CollectionBase. All database collections inherit from this class. I am considering refactoring to inherit from the g...

how to handle code that is deemed dangerous to change, but stable?

What is the best way to handle a big team that has access to a stable but no so pretty code, that is easy to introduce bugs into? I'm looking for something along the lines of SVN locking the file(s). ...

Why do you not declare several variables of the same type on the same line?

Why is it bad practice to declare variables on one line? e.g. private String var1, var2, var3 instead of: private String var1; private String var2; private String var3; ...

How do you refactor your old PHP code?

I have recently gotten involved in a project where a web-based game uses an engine written in PHP. The game works fine but could be more robust and have some more features - and the code is both old and fairly ugly. The issue with this code (and much PHP code in general I suspect) is that it has evolved to where it is and isn't structu...

The ultimate MySQL legacy database nightmare

Table1: Everything including the kitchen sink. Dates in the wrong format (year last so you cannot sort on that column), Numbers stored as VARCHAR, complete addresses in the 'street' column, firstname and lastname in the firstname column, city in the lastname column, incomplete addresses, Rows that update preceeding rows by moving data fr...

Rails-like Database Migrations?

Is there any easy to install/use (on unix) database migration tools like Rails Migrations? I really like the idea, but installing ruby/rails purely to manage my database migrations seems overkill. ...

Sorting a dict on __iter__

I am trying to sort a dict based on its key and return an iterator to the values from within an overridden iter method in a class. Is there a nicer and more efficient way of doing this than creating a new list, inserting into the list as I sort through the keys? ...

Tips on refactoring an outdated database schema

Being stuck with a legacy database schema that no longer reflects your data model is every developer's nightmare. Yet with all the talk of refactoring code for maintainability I have not heard much of refactoring outdated database schemas. What are some tips on how to transition to a better schema without breaking all the code that r...