refactoring

How to refactor this MySQL code?

SELECT AVG(`col5`) FROM `table1` WHERE `id` NOT IN ( SELECT `id` FROM `table2` WHERE `col4` = 5 ) group by `col2` having sum(`col3`) > 0 UNION SELECT MAX(`col5`) FROM `table1` WHERE `id` NOT IN ( SELECT `id` FROM `table2` WHERE `col4` = 5 ) group by `col2` having sum...

Refactoring exercise with generics

I have a variation on a Quantity (Fowler) class that is designed to facilitate conversion between units. The type is declared as: public class QuantityConvertibleUnits<TFactory> where TFactory : ConvertableUnitFactory, new() { ... } In order to do math operations between dissimilar units, I convert the right hand side of the oper...

c++ templates and inheritance

Hey, I'm experiencing some problems with breaking my code to reusable parts using templates and inheritance. I'd like to achieve that my tree class and avltree class use the same node class and that avltree class inherits some methods from the tree class and adds some specific ones. So I came up with the code below. Compiler throws an e...

VS API to facilitate a process to automate fixing of code breaks after refactoring.

I have found myself countless times reorganizing our solution (72 + projects), in efforts to reduce code. A lot of times it involves pulling out common types/libraries and moving them around. It always involves a reptitive compiler error so i am having to fix the same compiler error in a lot of different places. I am looking for a gu...

Using a part of a class in multiple projects

I have a set of methods that do some utility work over SQL connection, and until now these have been copied over from project to project. But as time goes on, project numbers have grown and I need to keep these methods in sync in case I find a bug or need to update it. I have managed to get it to the state that SQL access class is a par...

Cluttered code (almost complete): refactor it now or later?

I have a very cluttered code, and the current revision is almost complete, meaning all functionalities i wanted for this revision/sprint are done. Should i finish this revision as it is and refactor it later or should i refactor it right now? ...

Updated list of refactoring support for different IDEs

Does anyone know of an updated list of refactoring support for different IDEs? How many of Fowler's refactorings have tool support in popular IDEs? And does any IDE use code smells to any greater extent? I guess one would have to use addons for some IDEs, so even if I did find an updated list of refactoring support for say Eclipse, tha...

Refactoring C# via VIM/Emacs/Textmate etc

Is there some library which I could wrap so I could call it from the commandline and run refactorings like extract method from Textmate or Vim? I am mainly thinking about on the Mono framework. ...

Avoiding "variable might not have been initialized"

I recently ran across a routine that looks something like this: procedure TMyForm.DoSomething(list: TList<TMyObject>; const flag: boolean); var local: integer; begin if flag then //do something else local := ExpensiveFunctionCallThatCalculatesSomething; //do something else for i := 0 to list.Count do if flag then ...

jquery small refactoring , json call

Hi everybody, I need you suggestion to make some refactoring in jquery code because now it looks terrible for me. I have 4 json calls but the difference it is just the URL call. EX: var userId = MyuserID; var perPage = '45'; var showOnPage = '45'; var tag = 'tag1'; var tag1 = 'tag2'; ...

Refactoring PL/SQL triggers - extract procedures

Hello, we have application where database contains large parts of business logic in triggers, with a update subsequently firing triggers on several other tables. I want to refactor the mess and wanted to start by extracting procedures from triggers, but can't find any reliable tool to do this. Using "Extract procedure" in both SQL Devel...

Cut and Paste Code Reuse - JavaScript and C#

What is the best tool(s) for tracking down "cut and paste reuse" of code in JavaScript and C#? I've inherited a really big project and the amount of code that is repeated throughout the app is 'epic'. I need some help getting handle on all the stuff that can be refactored to base classes, reusable js libs, etc... If it can plug into Vis...

Python: does it make sense to refactor this check into its own method?

I'm still learning python. I just wrote this method to determine if a player has won a game of tic-tac-toe yet, given a board state like: '[['o','x','x'],['x','o','-'],['x','o','o']]' def hasWon(board): players = ['x', 'o'] for player in players: for row in board: if row.count(player) == 3: return player top, m...

vestal_versions and htmldiff question of reversion...

I'm guessing there's probably an easier way to do what I'm doing so that the code is less unwieldy. I had trouble understanding how to use the revert_to method... i wanted something where i could call up two different versions at the same time, but this doesn't seem to be the way that vestal_versions works. This code works, but I'm won...

frequently merge changes between branch and trunk?

My team and I are using svn branches for the first time. Before, we use to work only from the trunk. Over the past 2 weeks, we've been refactoring and developing new code against our branch. But during that time, another developer has been making bug fixes to code in the trunk and deploying it to the production server. We would like...

Refactoring a C# derived class with method dependancies

Hi Folks, I want to get your opinion on this. I have a class which is derived from a base class. I don't have control over the code in the base class and it is critical to the system that I derive from it. In my class I inherite two methods that are critical to the system and are used in pretty much every function, many times. I inte...

Is TDD broken in Python?

Hi! Assume we have a class UserService with attribute current_user. Suppose it is used in AppService class. We have AppService covered with tests. In test setup we stub out current_user with some mock value: UserService.current_user = 'TestUser' Assume we decide to rename current_user to active_user. We rename it in UserService but ...

are projects with high developer turn over rate really a bad thing?

I've inherited a lot of web projects that experienced high developer turn over rates. Sometimes these web projects are a horrible patchwork of band aid solutions. Other times they can be somewhat maintainable mosaics of half-done features each built with a different architectural style. Everytime I inherit these projects, I wish the ...

Automate refactor import/using directives, using ReSharper and Visual Studio 2010

I want to automate the Visual Studio 2010 / Resharper 5 auto inserting import directives to put my internal namespaces into the namespace sphere. Like this: using System; using System.Collections.Generic; using System.Linq; using StructureMap; using MyProject.Core; // <--- Move inside. using MyProject.Core.Common; // <--- Mov...

Removing a pattern from the beggining and end of a string in ruby

So I found myself needing to remove <br /> tags from the beginning and end of strings in a project I'm working on. I made a quick little method that does what I need it to do but I'm not convinced it's the best way to go about doing this sort of thing. I suspect there's probably a handy regular expression I can use to do it in only a cou...