refactoring

Dependency Injection: What's wrong with good old-fashioned refactoring?

DI creates an extra layer of abstraction so that if your implementation class ever changes you can simply plug in a different class with the same interface. But why not simply refactor when you want to use a different implementation class? Other languages like Python and Ruby work fine this way. Why not Java? ...

Refactoring many nested ifs or chained if statements

Hi, I have an object with large number of similar fields (like more than 10 of them) and I have to assign them values from an array of variable length. The solution would be either a huge nested bunch of ifs based on checking length of array each time and assigning each field OR a chain of ifs checking on whether the length is out of...

Visual Studio - plugin finding/removing dead code?

Anyone knows any free Visual Studio add-in that would find and/or delete dead (unused) code? I saw such possibility in MZ-Tools, but it's a little expensive as for private use ;) ...

How to refactor method which performs multiple steps (dependent on each other)?

What is the best way to refactor a method which has many steps in it? For example, a method which setups some objects, creates several objects (Eg a database table), and so on - basically, one method which does a set of related steps. Would this be best suited to the command design pattern? Thanks ...

Refactor the following two C++ methods to move out duplicate code

I have the following two methods that (as you can see) are similar in most of its statements except for one (see below for details) unsigned int CSWX::getLineParameters(const SURFACE & surface, vector<double> & params) { VARIANT varParams; surface->getPlaneParams(varParams); // this is the line of code that is different Sa...

Can someone help me refactor this C# linq business logic for efficiency?

I feel like this is not a very efficient way of using linq. I was hoping somebody on here would have a suggestion for a refactor. I realize this code is not very pretty, as I was in a complete rush. public class Workflow { public void AssignForms() { using (var cntx = new ProjectBusiness.Providers.ProjectDataContext())...

Ctrl+R, Ctrl+R command not working

I'm attempting to use the Ctrl+R, Ctrl+R command within Visual Studio 2008 to rename a variable. I get an error message at the bottom saying that "The key combination (Ctrl+R, Ctrl+R) is bound to command (&Rename...) which is not currently available." I am not running it or anything I can think of which might prohibit modifications o...

C# searching for new Tool for the tool box, how to template this code

All i have something i have been trying to do for a while and have yet to find a good strategy to do it, i am not sure C# can even support what i am trying to do. Example imagine a template like this, repeated in manager code overarching cocept function Returns a result consisting of a success flag and error list. public Result<...

Refactor java code

Okay guess this question looks a lot like: http://stackoverflow.com/questions/519422/what-is-the-best-way-to-replace-or-substitute-if-else-if-else-trees-in-programs consider this question CLOSED! I would like to refactor code which looks something like this: String input; // input from client socket. if (input.equals(x)) { doX();...

Reducing Code Repetition: Calling functions with slightly different signatures

Suppose I have two functions which look like this: public static void myFunction1(int a, int b, int c, string d) { //dostuff someoneelsesfunction(c,d); //dostuff2 } public static void myFunction2(int a, int b, int c, Stream d) { //dostuff someoneelsesfunction(c,d); //dostuff2 } What would be a good way to avoi...

How should I do a loop a nokogiri search in ruby?

I have the following that I retreive the title of each url from an array that contains a list of urls. require 'rubygems' require 'nokogiri' require 'open-uri' @urls = ["http://google.com", "http://yahoo.com", "http://rubyonrails.org"] @found_titles = Array.new @found_titles[0] = Nokogiri::HTML(open("#{@urls[0]}")).search("title").inn...

Can I stop Visual Studio from refactoring outside the current project?

I'm working in a class library and there are other source projects associated with the same solution. Is there a way for me to stop the VS refactoring tools from traversing those other projects, without removing them from the solution, but keeping everything the same? The reason I'm asking is because I often know the changed symbol does...

Is it possible to refactor this C# if(..) statement?

Hi folks, simple question :- i have the following simple if (..) statements :- if (foo == Animal.Cat || foo == Animal.Dog) { .. } if (baa == 1|| baa == 69) { .. } is it possible to refactor these into something like ... DISCLAIMER: I know this doesn't compile .. but this is sorta what i'm trying to get... if (foo == (Animal.Cat |...

Why do people have to use multiple versions of jQuery on the same page?

I have noticed that sometimes people have to use multiple versions of jQuery in the same page (See question 1 and question 2). I assume people have to carry old versions of jQuery because some pieces of their code is based on an older version of jQuery. Obviously, this approach causes inefficiency. The ideal solution is to refactor the o...

Why .NET Boolean has TrueLiteral and TrueString?

Why in Boolean type there are two fields with the same value? internal const int True = 1; internal const int False = 0; internal const string TrueLiteral = "True"; internal const string FalseLiteral = "False"; and public static readonly string TrueString; public static readonly string FalseString; static Boolean() { TrueString ...

How can I swap or replace multiple strings in code at the same time?

Given the following code sample: uint8_t i, in, ni; i = in = 2; ni = 1; while (2 == i > ni) in++; How can I replace i, in, and ni, respectively with either in, ni, and i or inni, inin, and nini using emacs, vi, *nix commands, or anything else? ...

how to refactor user-permission system?

Sorry for lengthy question. I can't tell if this should be a programming question or a project management question. Any advice will help. I inherited a reasonably large web project (1 year old) from a solo freelancer who architected it then abandoned it. The project was a mess, but I cleaned up what I could, and now the system is mor...

Is there a strategy to back-port C# code?

Hi all, I intend using the Argotic framework in support of a .Net Atom server. Unfortunately my target server (over which I have no control) only has .Net 1.1 - any the Argotic library is only in .Net 2 and 3.5. So, I now need to back-port the code to 1.1. Can anybody provide any strategic tips for this undertaking? I'm aware of the ...

Xcode raises exception when refactoring

When I run a refactor on my code in xcode, all the files are correctly refactored except one, and when I click to check the changes made in that file, the following 'Internal Error Occurs': Uncaught Exception: Invalid parameter not satisfying: fileName Stack Backtrace: The stack backtrace has been logged to the console. Here is what ...

Is it better to create methods with a long list of parameters or wrap the parameters into an object?

Hi, Is it better(what is the best practice) to create methods with a long list of parameters or wrap the parameters into an object? I mean lets say i have a Client data type with a long list of properties and i want to update all the properties at once. is it better to do something like public int Update(int id, string name, string su...