refactoring

StackOverflowError while Refactoring

I'm trying to refactor a package name (pretty near the root of the project hierarchy), and I'm getting the following error (flash builder 4): A fatal error occurred while performing the refactoring An unexpected exception occurred while creating a change object. See the error log for more details. The log file looks like this.... !...

Can I automatically refactor an entire java project and rename uppercase method parameters to lowercase?

I'm working in a java project where a big part of the code was written with a formatting style that I don't like (and is also non standard), namely all method parameters are in uppercase (and also all local variables). On IntellJ I am able to use "Analyze -> Inspect Code" and actually find all occurrences of uppercase method parameters ...

Need help refactoring this Javascript if/else statement

Here's my current if/else statement: var current_class = $(this).closest("article").attr("class") if (current_class == 'opened') { $(this).closest("article").removeClass('opened'); $(this).closest("article").addClass('closed'); } else { $(this).closest("article").removeClass('closed'); $(this).closest("article").addClass('opene...

whats the best pattern for removing this duplication

I have the following code I am trying to consolidate. (here are two examples) but with this repeated pattern of checking if fields are null then if they are different and if yes, then setting the new value into the old value. What is the best way to rewrite this to avoid duplication? if (String.IsNullOrEmpty(f.FirstName)) { i...

Refactoring long statement in Python

I have a very long conditional statement for deciding what action to take for a pair of variables a and b. action = 0 if (a==0) else 1 if (a>1 and b==1) else 2 if (a==1 and b>1) else 3 if (a>1 and b>1) else -1 While it is nice with the compactness (in lines;) ) of this statement, it must exist a more elegant way to do this? ...

Generalizing / Refactoring the code

Hi , My code is something like this : if(country == china) { getCNData(); } else { getDefaultDataForallCountries(); } Now I need to add similar logic as CN for some other country say US . The option available to me is to add one more country check in if condition and make it like if(country ==china && country==US){ getCNandUSD...

How can this IF statement code snippet be Refactored?

I've read a lot of Refactoring literature as of late and a common theme I see in examples is the reduction of lots of IF statements. The below is a very simple code block that first checks to see if an email address is supplied and if so, then proceeds to validate the email address. I typically see a lot of this type of code which always...

C# IDisposable object for entire class

The project that I'm working on at the moment uses an IDisposable object in every method in a class. It has started getting tedious re-typing the using block at the start of every method, and was wondering if there was a way to specify a disposable variable for use in every method of the class? public static class ResourceItemRepository...

rule of thumb when coding large nested functional blocks

Hello All, I’ve been coding in c# for a while now and generally have a good idea about the rule of thumb for coding standards. I’ve been recently encourage by my colleges to adopt a results based approach to coding functional blocks rather than nesting blocks of logic and am seeking your advice. Below is an example of what I’m talking ab...

Eclipse/Java: Is there a way to move a field from one class to another and update the references automatically?

I'm working on code that's a bit of a mess right now and am doing a lot of refactoring. Is there a way to move a field from one class to another and update the references automatically? I've used Eclipse's refactoring capabilities quite a bit, but I can't figure out a way to automate this. For instance, ideally I would drag the privat...

What's the OO way of refactoring these two very similar classes in PHP?

I have a class like the following: class DreamsImagesStore { public $table = 'dreams_images'; public function insertNewDreamImage($dream_id, $pid) { try { $values = array($dream_id, $pid); $sth = $this->dbh->prepare("INSERT INTO {$this->table} (dream_id, pid) ...

optimising aggregates with and without a condition in ms sql

Hi, I would like to get a sum from a column, with and without a condition. The code I have now is SELECT regular.id, regular.sum as regularsum, special.sum as specialsum FROM (SELECT Sum(stuff) as sum, id FROM table WHERE commonCondition = true GROUP BY id) as regular INNER JOIN (SELECT Sum(stuff) as sum, id FROM table Where commo...

Refactoring: Getting rid of an optional variable for a function

Here's the situation; below is a piece of PHP code which is frequently reused. if (! isset($_REQUEST['process_form']) { // render form echo "<form>"; // snipped // important bit! Remember which id we are processing echo "<input hidden='id' value='$id'>"; // snipped } else { // process the form } I wish to encapsu...

Is there a ReSharper-like tool for C++ projects?

I'm searching tool like ReSharper for C++. I want to have a more flexible refactoring tool than Visual Assist. It is really really good but if there exists a tool like ReSharper for C++, I want to know the tool's name. ...

Namespace refactoring tool for Eclipse?

I'm doing some housekeeping on some files, and I need to move some classes to a new namespace. Currently I have to manually edit the files, but I was wondering if there's a more efficient way of doing this? I heard about ReSharper for Visual Studio does what I need, but is there a similar tool for Eclipse? ...

How to detect useless Delphi units in the interface and implementation uses clauses?

Possible Duplicate: How can I identify and get rid of unused units in the uses clause in Delphi 7 ? Is there a wizard/tool to automatically detect all useless units? If in the current unit I "use classes" but in practice I don't need it I can of course manually remove Classes. But how can I do this automatically for all units...

moving tables between databases

For a bit fall cleaning, I am moving 25 tables between MySQL databases (different pieces of hardware). This is not the WHOLE database, just 25 tables out of a few hundred... These tables don't really belong in there, I won't go into why for NDA reasons. Now, this is going to break a lot of code and sql queries. What is the best way t...

Dynamically checking the value of a radio button (refactoring question)

I wrote this jsfiddle based largely on the example found here. The example is over 2 years old so I was wondering if there is an easier way to check the value of a radio button than gobs of if, elseif, else statements. My values are going to be disabled, both, footer, header so with only four not too bad. I'm just trying to learn how to...

Simplifying overly complicated LINQ query - queries

public partial class MembershipModule : BaseEntity<MembershipModule> { /// <summary> /// Returns wheter a module is accessible /// </summary> public static bool IsAccessible(MembershipModule module) { // In absence of a module, no security applies to the page if(module == null) return true;...

rails refactoring tips

Hi, I have been building a large scale rails app and it has come time to refactor it. What tips can you offer me, or resources can you point me to? I am especially interested in making my database calls more efficient. ...