refactoring

Use "convert to auto property" on multiple properties at once

I find myself using Resharper's "convert to auto property" refactoring a lot to remove pre C# 3.0 boilerplate code. Is there a way I can apply this to all properties in a single class at once? ...

Bulk Refactoring C#

I want to be able to refactor 500 projects at the same time. I have about 20 solutions and I don't have a master solution with everything because I haven't figured out a way to auto generate it. Any suggestions? Thanks Edit I've tried slnTools from codeplex to generate a solution and visual studio pretty much took down the entire ...

Flatten conditional as a refactoring

Consider: if (something) { // Code... } With CodeRush installed it recommended doing: if (!something) { return; } // Code... Could someone explain how this is better? Surely there is no benefit what so ever. ...

Order of Methods within any Class

I'm still very new to programming and I want to write the cleanest code possible. This may sound like a silly question, but what order should I put my methods in? Functionally of course it doesn't matter, but layout it makes a huge difference. So say we have the following code in one class: -(void)testCreateProjectWithStartDate { [...

Creating and executing a Merge Replication programatically

Let me preface this by saying I now realize how stupid I am and was. I have been developing for 1 year (to the day) and this was the first thing I wrote. I now have come back to it and I can't make heads or tails of it. It worked at one point on a very simple app but that was a while ago. Specifically I am having problems with Local...

How to refactor a trigger that uses the inserted and deleted tables, to move common code to a stored procedure

I have a trigger that will be dynamically created, as it will be attached to a view that is also dynamically generated. I don't want my stored procedure to have the entire trigger within it, so I would like to move most of it to a stored procedure, but I won't know the fields in the inserted and deleted tables. The trigger is about 90 ...

How to refactor this Ruby (controller) code?

This is the code in my reports controller, it just looks so bad, can anyone give me some suggestions on how to tidy it up? # app\controller\reports_controller.rb @report_lines = [] @sum_wp, @sum_projcted_wp, @sum_il, @sum_projcted_il, @sum_li,@sum_gross_profit ,@sum_opportunities = [0,0,0,0,0,0,0] date = @start_date num_of_...

How to do massive search and replace in emacs?

Possible Duplicate: Using Emacs to recursively find and replace in text files not already open Duplicate: using-emacs-to-recursively-find-and-replace-in-text-files-not-already-open I need to to regexp search and replace on a list of files. Is there an emacs command (command combo) for that? Or maybe you have a better way to...

How do I refactor Perl code that uses Template Toolkit with DBI to take advantage of FastCGI?

Background Below is a typical piece of Perl code (sample.pl for the sake of discussion) that grabs submitted form data using CGI, passes the form data to DBI which will then retrieve the required rows from MySQL and then hands the results over to Template Toolkit to render into a HTML document for display. Code listing for sample.pl : ...

Is this possible with Visual Studio snippets?

I use a modified form of TODO comment (SteveC_TODO) that allows me to group my own todos together in the task list. Yesterday I thought it would be nice to modify the refactoring snippets to add a todo comment to the usual NotImplemented exception. I modified the Method Stub - Body snippet to this $signature$ { //SteveC_TODO: impleme...

How to cast an interface to its sub interface?

Hello SOers, imagine you have the following interfaces: public interface IInterfaceA : IInterfaceX { // // declarations // } public interface IInterfaceB : IInterfaceX { // // declarations // } public interface IInterfaceC : IInterfaceX { // // declarations // } Now I want to replace the followin...

Removing logic from partial views in ASP.NET MVC

I am aware that views should not have code in them but in a project I am working on I have a lot of logic in the views. My home page has <% Html.RenderPartial("SearchResults"); %> Now in the partial view I have an aweful lot of logic like this; <div id="RestaurantsList"> <%if (Model.restaurantsList.Count() > 0) { foreach (var ...

Refactoring repeated If statement blocks

I have some code that I'm trying to rewrite. The code is designed to be "generic", in that it can be used by many different callers that require different "work flows". It goes something like this: string globalA; int globalB; bool globalC; // Lots more globals in various shapes and forms void TheOneAndOnlyMethod(XmlBasedConfig config)...

Sorting a string that could contain either a time or distance

I have implemented a sorting algorithm for a custom string that represents either time or distance data for track & field events. Below is the format '10:03.00 - Either ten minutes and three seconds or 10 feet, three inches The result of the sort is that for field events, the longest throw or jump would be the first element while for ...

How should I rewrite a very large compound if statement in C#?

In my C# code, I have an if statement that started innocently enough: if((something == -1) && (somethingelse == -1) && (etc == -1)) { // ... } It's growing. I think there must be 20 clauses in it now. How should I be handling this? ...

How to avoid hardcoded field names in HQL, Hibernate?

Suppose that I have the following HQL: String hql = "select e.aField from MyEntity as e"; If I want to refactor and change the name of the MyEntity's member variable aField to something else, I also have to change all occurrences in the whole code in Strings. If I forget to change one hql string the code breaks. How can I avoid this ...

Refactoring or Rewriting Monolithic PHP Spaghetti Codebase

I've inherited a really poorly designed PHP spaghetti code project. It's been gaining a good bit of traffic recently and is starting to have performance issues on top of the poor monolithic code base. Its maxing out performance on a chunky 16GB dedicated machine when it really shouldn't be. I'm planning on doing some performance twe...

When do you refactor code?

Do you do it when you’re in the code doing something else? When your manager approves it? (Seems this never happens) I guess some of this depends on the impact of the changes. If I change the code and it affects nothing outside of the class, to me that is low impact. What does it become a design change? When it effect X object or X pr...

What's a good way to refactor a growing number of javascript/jquery functions?

I'm working on a project where we are doing a lot of custom javascript and especially jquery, on an mvc style project. The only problem is that I keep adding more and more global functions/variables and they are piling up. I've got a few files but I'm unsure how to split some of the stuff up into separate files. I've thought about co...

What simplest avoidable ugly code issue?

My first thoughts are too many lines of code in a method. In most cases it's easy to break something apart into multiple methods at least. I have many more, but that seems to be one of the simplest to avoid. It really bugs me to see a method with 1000 lines of code, this also seems to be a common problem. Anything where you need to scr...