refactoring

Find completely commented files

In a solution with lots of files and projects - how would you find all completely commented files? I assume that every line of code starts with // (EDIT: or is empty) in such files. I am using VS 2008, C#, ReSharper is available. I know, normally such files should not exist - that's what a source safe is for ... ...

Using old code to verify results in unit tests

Lets says I'm replacing an over complicated method with a much simpler implementation that I believe does the same thing. Would it make sense for me to copy the old code into a class with my unit tests so I can assert the result of both is the same? Thanks ...

What Visual Studio add-ins do you use for C++ refactoring?

I have just started using Visual Assist X for C++ refactoring in Visual Studio 2008. It is quite good, but IMO, not to the same level as what ReSharper has for C#. I am wondering what people are using for C++ refactoring, especially for larger code base. Here are the add-ins that I have tried so far: * Visual Assist X * Refactor! Pro M...

How to fundamentally re-architect a system whilst preserving functional behaviour?

I have inherited an ASP.NET application that is a disaster architecturally, however it works and it is in live production use. In order to enhance the application in the future I need to totally re-architect it, but I need to preserve the existing front-end functionality - the changes that are being asked of me are more backend integrati...

refactoring multiple if-else conditionals in a method

I am in the process of refactoring my existing code. It actually works fine, but it is a bit cluttered with multiple if-else conditionals checking the value of one variable and change the value of a second variable to an updated value taken from a fixed enumeration structure. else if (var1 == 'valueX') { if (var2 == MyEnum.A) var2 = ...

Refactoring Windows Forms Application

I am developing a windows forms application. It was basically evovled with a mix of BDUP and prototyping. I have about 1500 lines of code (excluding IDE generated partial class... 1465 to be exact) in the form and the form has 6 tabs (9 subtabs). Does not have more than 10 controls in each form so multiple form solution would be an ...

Python: prefer several small modules or one larger module?

I'm working on a Python web application in which I have some small modules that serve very specific functions: session.py, logger.py, database.py, etc. And by "small" I really do mean small; each of these files currently includes around 3-5 lines of code, or maybe up to 10 at most. I might have a few imports and a class definition or two...

Can you refactor this ?

Can you refactor this ? private void ClearUserDataFields() { var textBoxes = this.Controls.OfType<TextBox>(); foreach (var txtBoxControl in textBoxes) { txtBoxControl.Text = String.Empty; } } Isn't there anyway to do this in one LOC ? ...

How use refactoring tools when you have multiple visual studio solutions?

We have two visual studio solutions for our product: one for our reusable components (Core.sln) and one for our product (Product.sln). Projects from the Product solution have references (file references) to assemblies of our core. When working in one solution, the refactoring features will not refractor in the other solution. Renaming a...

Is it possible to use a Strategy pattern for data structure with no common ancestor?

I have two data structure classes (this is a simplified version of my code) Animal: Has one property “int Age” Person: Has one property “DateTime Birthday” What I am trying to accomplish is to compile “Uploading” (persisting to database), which is common across all different data structure classes. So mainly my goal is to have a s...

Delphi 2009 refactoring error

I use Delphi2009. When using Refactoring -> Change Params every time when I try to add new parameter to routine, when I setup new parameter and click “Refactor” I get an error: (NOTE: imageshack sometimes has problems, so sometimes you may not see this image). Do you know any workaround? ...

Using properties in switch statement cases?

I have a switch statement in one class that generates Command objects, based on if a certain line in a code file matches the particular code for that Command object. like this: switch (line): { case "#CODE1": return new Command1(); case "#CODE2": return new Command2(); } I want to turn it into something like this:...

regex for that excludes matches within quotes

I'm working on this pretty big re-factoring project and I'm using intellij's find/replace with regexp to help me out. This is the regexp I'm using: \b(?<!\.)Units(?![_\w(.])\b I find that most matches that are not useful for my purpose are the matches that occur with strings within quotes, for example: "units" I'd like to find a way...

How many tables/sprocs/functions in a database is too many?

I'm interested in database refactoring. I deal with several databases that don't have a large amount of data, just a few GB with at most a few hundred thousand rows. However, they have hundreds -- sometimes many hundreds -- of tables, views, sprocs and functions. In some places a divide-and-rule strategy using schemas has been implemente...

What does refactoring mean to you?

Hi, bit of a subjective question but - I'm not looking for a definition, I'm more interested in what it means to you? What does refactoring mean to you? ...

C# refactor this messy code!

I am basically creating a flat View Model for a Timesheet page (ASP.NET MVC) that has a grid for the days of the week. The WorkTime properties should either be an existing WorkTime from the database or null if there is no existing one. There will only ever be 1 week displayed (Saturday to Friday). and I have the individual properties th...

Converting bytes to GB in C#?

I was refactoring some old code and came across the following line of code to convert bytes to GB. decimal GB = KB / 1024 / 1024 / 1024; Is there a better way to refactor the following piece of code? Update I meant to say bytes to Gigabytes. I gave wrong information. ...

C# Generics Refactoring

Hi All, I am trying to refactor a piece of code which seems easily refactorable but is proving difficult. There are two method which seem very similar and I feel should be refactored:- public class MyClass { private void AddBasicData(Receiver receiver) { var aHelper = new AHelper(); var bHelper = new BHelper();...

C# Assign a delegate based on a type - refactor help?

Hi All, I had a quick question. Something seems really wrong with this code. I want to take advantage of generics and delegates and quite possibly generic delegates if applicable. I am working with some code generated api's and the objects generated are very similiar. I see that they all implement an interface so I was to try to create o...

When should you not refactor?

We all know that refactoring is good and I love it as much as the next guy, but do you have real cases where is better not to refactor ? Something like time critical stuff or synchronization? Technical or human reasons are equally welcome. Real cases scenarios and experiences a plus. Edit : from the answers thus far, it looks like the...