refactoring

Guess this goto label...

I was about to refactor this following VB6 code (written by someone else). Public Function GetValue(ID As Long) As Boolean On Error GoTo eh '' ... DAL Logic... eh_Exit: On Error GoTo 0 Exit Function eh: Resume eh_Exit End Function What do you think the original author's intention was for the label eh? Probably Just "eh, som...

C# Linq Code Refactoring

The code below is what I currently have and works fine. I feel that I could do more of the work I am doing in Linq instead of C# code. Is there is anyone out there who can accomplish the same result with more Linq code and less C# code. public List<Model.Question> GetSurveyQuestions(string type, int typeID) { using ...

Python tool that suggests refactorings

When digging into legacy Python code and writing Python code myself, I often use pylint. I'm also using Clone Digger. I've recently started to use rope, which is a library for automated refactoring. But I'm looking for something else than rope. I would prefer a tool that just makes suggestions about possible refactorings: names the refa...

Typical C with C Preprocessor refactoring

Hi, I'm working on a refactoring tool for C with preprocessor support... I don't know the kind of refactoring involved in large C projects and I would like to know what people actually do when refactoring C code (and preprocessor directives) I'd like to know also if some features that would be really interesting are not present in any ...

Resharper change object to interface

I have an upgraded 3rd party library and there used to be an object called Foo and now its an interface called IFoo what is the best way to change all usages and declarations of Foo to IFoo i tried doing Find / Replace but this also affected FooBar to IFooBar (which i dont want) thoughts? ...

Find / Replace all files in namespace or folder

i know i can do find /replace in Current Document Current Project Current Solution is there anyway to do this in current namespace or current folder?? ...

Tricks to refactor a piece of code with many branches (if/then/else)

I'm having a hard time trying to refactor some pieces of code with many branches. There are many if/then/else blocks, some of them are nested. Are there any tricks that can be used to refactor the code without wasting a lot of time trying to understand every minor aspect of the functionality first? For now I'm basically using boolean a...

What is the optimal trade off between refactoring and increasing the call stack?

I'm looking at refactoring a lot of large (1000+ lines) methods into nice chunks that can then be unit tested as appropriate. This started me thinking about the call stack, as many of my rafactored blocks have other refactored blocks within them, and my large methods may well have been called by other large methods. I'd like to open th...

How to refactor tightly coupled classes?

I'm trying to refactor a big tightly coupled application and trying to make it more maintainable and flexible. I've got many unit tests, so I'm hoping to refactor step by step. Which Design & Refactoring Patterns should I consider implementing / applying to accomplish this task ? I can think of some : Extract Interface Extract Meth...

ruby loop refactor

Hi All, I have a loop that looks like this def slow_loop(array) array.each_with_index do |item, i| next_item = array[i+1] if next_item && item.attribute == next_item.attribute do_something_with(next_item) end end end aside from changing the way do_something_with is called, how can i make this perform better? thx, -C...

Should I make this a read only property or a function.

So in my COM wrapper I have a property like this: public string Name { get { //Call the COM object //Work the returned object //Return the name. } } I was doing some reading on read-only properties vs function and was wondering if I should change this to a function instead, something along the lines ...

Metrics for measuring successful refactoring

Are there objective metrics for measuring code refactoring? Would running findbugs, CRAP or checkstyle before and after a refactoring be a useful way of checking if the code was actually improved rather than just changed? I'm looking for trends we can capture that can help us improve the code review process without wasting time on cod...

Python tool that builds a dependency diagram for methods of a class

I'm digging into a huge legacy Python class that has a lot of methods. I eventually break complex ones into smaller pieces so the amount of methods increases even more. I wonder if there is a tool that can scan the Python code and build some kind of dependency diagram for its methods. I define method x() to be a dependency of method y()...

Do you look at which variables a method uses before refactoring a large class into smaller ones?

Hi all, I am interested in exploring the idea that the relationship between methods and the member varialbes they use can give a hint to how the class could be broken up into smaller pieces. The idea is that a group of variables will be closely related to one responsibility and should be contained in one class according to SRP. For a t...

Refactoring an enable/disable button toggle function.

I have the following simple function: private void EnableDisable941ScheduleBButton() { if (this._uosDepositorFrequency.Value != null) this._btnScheduleB.Enabled = ((int)this._uosDepositorFrequency.Value == 0); } It's a member of a Winform class which I'm trying to split into a passive view and presenter. It's obvious there ...

Refactoring with Lambda's and Delegates

I've just installed VS2008 and have run into a problem that I'm sure can be solved with either lambda's or delegates (or a combination!). private string ReadData(TcpClient s, string terminator) { // Reads a byte steam into a string builder until either data is unavailable or the terminator has not been reached va...

What is the reason behind JSLint saying there are "too many var statements"

JSLint (with the onevar flag turned on) is flagging some javascript code that I have with the following: Problem at line 5 character 15: Too many var statements. I am happy to fix these errors, but I'd like to know, am I doing it for performance or because it is just a bad practice and has a greater potential to introduce bugs in my ja...

Python: avoiding pylint warnings about too many arguments

I want to refactor a big Python function into smaller ones. For example, consider this following code snippet: x = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 Of course, this is a trivial example. In practice, the code is more complex. My point is that it contains many local-scope variables that would have to be passed to the extracted...

Refactoring strategy for the class which generates specific text file

Hi guys, I am a TDD noob and I don't know how to solve the following problem. I have pretty large class which generates text file in a specific format, for import into the external system. I am going to refactor this class and I want to write unit tests before. How should these tests look like? Actually the main goal - do not break th...

Refactoring of a large C++ function

At work we have a legacy process written in Visual C++ that basically consists of a single 5000 line function. In essence the program is just one big case statement with similar cut-and-pasted code handling a fair amount of the logic for case. Obviously we would like to refactor this code to extract these cases out into separate function...