refactoring

.Net Refactoring application to use Dependency Injection

I am currently into the testing stage of a project I am working on and am having trouble bringing the main service under test in anything other than the most basic default test cases. The Service is currently responsible for the creation of all sub-components, which I would like to change to use an IoC container. What container should...

Should you wrap 3rd party libraries that you adopt into your project?

A discussion I had with a colleague today. He claims whenever you use a 3rd party library, you should always write for it a wrapper. So you can always change things later and accomodate things for your specific use. I disagree with the word always, the discussion arose regarding log4j and I claimed that log4j has well tested and time p...

Simple codeigniter refactoring question -- best practice

Hi all, I have a quick question about refactoring php code. Below are three functions. The first two appear quite similar, and only differ with one if statement. The third combines the first two through use of a flag. Is this the best practice? Here it seems okay to use a flag, but what if we need to add more flags in the future?...

Why does ReSharper's "Rename" only sometimes display a prompt?

When I rename a variable using ReSharper 4.5 (VS2008), the rename is performed inline (I specify the new variable name in the editor itself) or via a prompt (a popup window where I specify the new variable name). I'm hoping someone can tell me what determines which approach is used? ...

Good Non-Commerical (free) Refactoring Tool for Visual Studio 2005/Visual C++ 8.0?

We have a rather large codebase in C++ here that needs some refactoring; since it's generally bad to start from scratch, I was wondering if there were any good free code refactoring tools for Visual Studio 2005/Visual C++ 8.0? ...

refactoring best practices for both PHP and Ruby on Rails

Hi, Wondering if someone can suggest a refactoring 'best practice' or more ideally a "check-list" that we can go through and refactor against common issues. Some of these ideas were pretty good: http://my.safaribooksonline.com/9780321620293 But looking for more. Thanks. ...

Why does my http response body suddenly contain a load of gibberish?

I'm trying to refactor an existing asp.net-mvc web application and introduce mvc-turbine. The application works as is, but I want to make it more pluggable and maintainable so future maintenance will be easier. I figured I'd try to keep the refactoring steps as small as possible, so I referenced MvcTurbine, MvcTurbine.Unity and MvcTurbi...

What name should I give my function? And who can I ask next time?

Background: There are a few threads on SO about how to choose names for variables and functions. It dawned up on me that there might be a use for a site where you could go and ask random people what name a particular function should have. You describe the behavior, and they come up with a name. The benefit of this, you get multiple pers...

writing more efficient code in javascript

Hi all, I'm trying to write more readable and more efficient code, I've always hated if if if chains .. is it possible to write the following statement in some other more "elegant" way like maybe using ternary ops : if(text.length < 1){ if(errtext.length > 1){ errtext+="<br>"; } errors = true; errtext += "Field cannot be emp...

strategies for managing long class files in php

I've got a bunch of functions that I want to move into a class. They're currently split into a couple of fairly long files. I'd prefer not to have one 2500 line file, but as far as I can tell, you can't use include to split a class up into multiple files. In theory, I could group the functions in different classes, but they're closely re...

Is the Eclipse CDT Refactoring Project Dead?

I've been over to the site lately and nothing much seems to work (aside from the main page) ...

best way to refactor my form (procedural to oop?)

(Note: this is related to this question, but I think it could have been written more clearly, so I'm trying again -- my update only helped to a limited extent.) I've inherited some code that creates a complex form with numerous sections, and lots of possible views, depending on a number of parameters. I've been working with it for a whi...

How can I check that I didn't break anything when refactoring?

I'm about to embark on a bout of refactoring of some functions in my code. I have a nice amount of unit tests that will ensure I didn't break anything, but I'm not sure about the coverage they give me. Are there any tools that can analyze the code and see that the functionality remains the same? I plan to refactor some rather isolated...

How do I refactor three database operations that only differ by the method call?

I have three database operations like so: public void Add<T>(T entity) { using (var transaction = Session.BeginTransaction()) { if (entity is IEnumerable) { foreach (var item in (IEnumerable) entity) { Session.Save(item); } } else { ...

Using parameter to control Rails validations

I have an Event model with a finish_time field and a form checkbox called whenever. When whenever is checked I want to set finish_time to nil regardless of its value in parameters, when whenever is not checked I want to make sure that finish_time is a valid date before I save it in the database. Currently I am achieving this using a w...

Refactor this C# code to a more elegant version

I am trying to refactor this code into a more elegant version. Can anyone please help. The issue is where to as sign the first evaluation result for comparision later on? And I want to eliminate the use of if/switch if possible Should I remove Operator class and split Eval into And and Or class, but wouldn't be too much differnt I thi...

How to avoid long switch ..need help refactoring

hi guys, i needed help refactoring the following class, Following is a class Operation with variety of Operations in switch : i want to avoid the switch statement.I read few articles on using polymorphism and state pattern .but when i refactor the classes i dont get access to many variables,properties Im confused on whether to use o...

Inter-solution C# refactoring in VS

I have solution A which defines public class Foo, and solution B which references A and uses Foo. I rename Foo to Bar in A and use the "Update References" feature, but that only updates the references in the current solution. How do I go about updating them in solution B as well (automatically)? (note that search&replace isn't an option...

Ruby editing with intellisense

Hi there, Currently I am exploring the world of ruby. Playing around in the irb you get nice intellisense for like 5.<tab><tab>. I tried many editors/IDEs (mainly gedit, vim, radrails) with a couple of plugins. I kind of do not like the bloated eclipse-style environment but as far as I fount out it is the only one providing intellisense...

Link error LNK2005 when trying to compile several CUDA files togheter

I have a CUDA program that works fine, but that is currently all written in one file. I'd like to split this big file into several smaller ones, in order to make it easier to maintain and navigate. The new structure is : foo.cuh foo.cu bar.cuh bar.cu main.cu The .cuh header files contain structs and function prototypes, and the .cu f...