refactoring

Refactoring: Nested class or separate classes?

Hi, I'm currently doing some refactoring (+ adding new features) to some of our framework classes. The situation is that we have a single (god-like) class which does a bunch of logic we'd like to split up. The class represents something like a validation rule for fiscal codes. So it does validation of the names of the person, birthdate ...

Refactoring domain logic that accesses repositories in a legacy system

I am working with a legacy system that has an anemic domain model. The domain has the following entity classses: Car, CarType, CarComponent, CarComponentType. For each of these, there is a separate repository. There is also a number of services that access these repositories and contain basically all logic. I need to implement a metho...

create an interface from a huge class using resharper

Hi, I have a very big class with lots of methods, is it possible to build an interface from this class using resharper? ...

How to refactor this sql query

Hi, I have a lengthy query here, and wondering whether it could be refactor? Declare @A1 as int Declare @A2 as int ... Declare @A50 as int SET @A1 =(Select id from table where code='ABC1') SET @A2 =(Select id from table where code='ABC2') ... SET @A50 =(Select id from table where code='ABC50') Insert into tableB Select Case when @A1...

Help me refactor this loop

I am working on the redesign of an existing class. In this class about a 400-line while loop that does most of the work. The body of the loop is a minefield of if statements, variable assignments and there is a "continue" in the middle somewhere. The purpose of the loop is hard to understand. In pseudocode, here's where I'm at the re...

A more efficient way to work with DataSets

I have the following code, repeated on each Form, as part of the Update process. When the page loads the BLL returns a DataSet, say _personInfo = ConnectBLL.BLL.Person.GetPerson(personID); I store that DataSet in a Form level variable which I then use to check against for changes during the Validate/Update process. I pass a row at ...

Refactor help c#

I have several hundred lines of code like this: if (c.SomeValue == null || c.SomeProperty.Status != 'Y') { btnRecordCall.Enabled = false; } if (c.SomeValue == null || (c.SomeProperty.Status != 'Y' && c.SomeOtherPropertyAction != 'Y')) { btnAddAction.Enabled = false; } if (c.SomeValue == null || c.SomeProperty.Processing !=...

Who makes tools auto documenting/analysing legacy code and which is better?

Who else makes tools like Scitools Understand C++ and which is better? Looking for the most complete auto documentation tools for Ada, C, C++ and Fortran. For analysis of tool migration effort, to aid to in pruning dead code and identifying essential functionality. Pete ...

Is there a better way to do this LINQ statement block?

I'm relatively new with LINQ, but I'm going to be getting into it a lot more. Is the following a practical application of LINQ, or is there a better way to do something like this? Public Shared Function GetItems(ByVal itemsList As List(Of OrderItem), ByVal whichForm As ItemsFor, ByVal formID As Integer) As List(Of OrderItem) Dim item...

Turn off Visual Studio suggestions when using Resharper?

I just started playing with ReSharper and I think I know why ppl love it now :) I'm using Vs2008 TS and noticed I have in editor 2 suggestions currently: one, standard coming from VS, and second from ReSharper... Eg when I entere something like: int a = CalculateMe ( 10 ); (Note: CalculateMe method is not defined yet) So, I can see ...

Refactoring help with Ifs

I've been working on this code for awhile and for some reason all the if's are driving me crazy along with a bunch of repeated code. Is there a nicer more cleaner way to do this? public Program(string[] args) { try { WriteToLogFile("Starting ImportTask"); if (args.Length == 0) { ...

ASP.NET MVC: Ugly code needs refactoring (returning three values)...

Hello, I've been brooding over a design issue (smelly code kinda thing) for a couple days now. Maybe you can help. I have a "Login" Method in my RegistrationService, and currently it looks simplified like this: public Boolean Login(String username, String password, out String successRedirectUrl, ...

.NET Adding a range of characters to a list

Hi, I would like to ask if there is a more elegant way to do this: List<char> unallowed = new List<char>(); for (char c = '\u0000'; c <= '\u0008'; c++) { unallowed.Add(c); } for (char c = '\u000B'; c <= '\u000C'; c++) { unallowed.Add(c); } // And so on... I have to add to the list a few contiguous ranges of Unicode characte...

Keyboard Shortcut for Smart Tag in Refactor!

I am trying to get Refactor! for ASP.NET, CodeRush Xpress and Resharper play together. I installed Resharper, then CodeRush Xpress and then Refactor! for ASP.NET. I can't seem to get any menu options for Refactor! or CodeRush. The bracket highlighting is working so I know that it is loading, but the smart tag will not appear (the thre...

Removing tightly coupled code.

Forgive me if this is a dupe but I couldn't find anything that hit this exact question. I'm working with a legacy application that is very tightly coupled. We are pulling out some of the major functionality because we will be getting that functionality from an external service. What is the best way to begin removing the now unused cod...

Can you rewrite this snippet without goto...

Guys, I have the following code that is inside a big while loop that iterates over a tree. This is as fast as I can get this routine but I have to use a goto. I am not fundamentally against goto but if I can avoid them I would like to. (I am not trying to start a flame war, please.) The constraints: The current=current->child() is ex...

Thread-safety refactoring

I am trying to make a Java application thread-safe. Unfortunately, it was originally designed for a single-user mode and all the key classes are instantiated as singletons. To make matters worse, there is a whole bunch of interfaces working as constants containers and numerous static fields. What would be considered as a good practice in...

Refactor methods invoking delgates with different parameter signatures

Is there a pattern that I could apply to refactor this code? The only difference between the two methods is that that one method takes an extra parameter and passes it to the delegate? I found out that delegates cannot take overloaded method signatures. How could I add one more level of indirection? :) public static void ProcessFolder(...

What do you do with atrocious code?

What do you do when you're assigned to work on code that's atrocious and antiquated to the point where it's almost incomprehensible? For example: hardware interface code, mixed with logic, AND user interface code, ALL in the same functions? We see bad code all the time, but what do you actually do about it? Do you try to refactor ...

Writing a new refactoring plugin for Eclipse?

Is there any good documentation on implementing new refactorings in Eclipse? Specifically, I'd like to access the AST for a Java class, make some non-trivial changes, and save the result back to the source file. So far, the only documentation I've found is (1) the source code for the existing refactorings and (2) a few articles on the L...