refactoring

Excract JPanel into new class in NetBeans

This is similar to this question, except the code is already written. I have JFrame JTabbedPane JPanel X <...> JPanel Y <...> JPanel Z <...> all defined in the same class, but I want to move each panel into its own .java file. I really don't want to manually copy-paste from the underlying .form and .j...

Unit testing: Is it a good practice to have assertions in setup methods?

In unit testing, the setup method is used to create the objects needed for testing. In those setup methods, I like using assertions: I know what values I want to see in those objects, and I like to document that knowledge via an assertion. In a recent post on unit tests calling other unit tests here on stackoverflow, the general feelin...

Advantages/Disadvantages of Refactoring Tools

what are the advantages and disadvantages of refactoring tools, in general? ...

How to find references when refactoring rails application with textmate?

I have been practicing TDD in C# for several years now and recently have moved to Ruby on Rails full time. I am continuing the practice of TDD with RSpec. My question is regarding the process of finding references while refactoring. In Visual Studio I was addicted to Resharper's "find all references" when renaming or replacing methods. ...

Refactoring an If else tree

I have an if else tree that is going to grow as I add additional items for it to maintain and I'm looking at the best way to write it for maintainability I'm starting with this code private void ControlSelect() { if (PostingType == PostingTypes.Loads && !IsMultiPost) { singleLoadControl.Visible = true; singleTru...

When you're the new guy and you keep seeing dumb things - do you refactor them?

Do you refactor when you see things like this? Or do you just plug your nose and move on? public Collection<DataValidationRuleBase> GetFieldValidationRules(String key) { Collection<DataValidationRuleBase> found = null; try { this.mRules.TryGetValue(key, out found); } catch (Ar...

How to refactor global variables out of your code.

The discussion around global variables and their misuse seems to hold a a certain dogmatic tone to it. I am not here to dispute the "globals are bad" concept as it makes sense to me why they are bad. However I was wondering if people had some interesting code snippets that demonstrate exactly how to effectively refactor higher scoped var...

Refactoring With Reflection

I have several methods that populate a SQLCommand objects parameter collection from an object like this if (!String.IsNullOrEmpty(SearchObj.FirstName)) { command.AddParameter(Fields.FirstName, SearchObj.FirstName); } if (!String.IsNullOrEmpty(SearchObj.LastName)) { command.AddParameter(Fields.LastName, SearchObj.LastName); } if ...

Changing company name...do we change namespaces?

We plan on changing our company name starting October 1st. All of our namespaces, projects etc use XYZ.ComponentName. My question to you would be, on October 1st, what would you do? Change all the old components to ABC.ComponentName? Leave the old ones but any new development becomes ABC.ComponentName? Just stick with the old name? ...

Refactoring a whole project's variable and parameter names

I have inherited a large C# project where all the variable and parameter names are written_like_this. Is there some easy way or tool I could use to rename them all automatically with no more than say 10 mouse clicks. So that the above example would become writtenLikeThis (i.e. camel case). And instance variables _writtenLikeThis. It wo...

Cleaning up PHP, and cleaning up unnecessary code.

I'm still new to certain PHP functions. Is there any way I can clean up the following code, because I know all of this is just unnecessary, and it's giving me a headache. Everything after the if statement is the same for each set of code. if($class == "2"){if ($posts >= 1){ $sql = "UPDATE users SET posts=posts+1,tposts=tposts+1,poin...

Is there a working C++ refactoring tool?

Does anybody know a fully featured refactoring tool for C++ that works reliably with large code bases (some 100.000 lines)? I tried whatever i can find again and again over the last years: SlickEdit, Eclipse CDT. They all were not at all usable. SUMMARY: I took time and evaluated "Visual Assist X" as well as "Refactor for C++". Both h...

DRY unique objects in Django

I want to ensure an object is unique, and to throw an error when a user tries to save it (e.g. via the admin) if not? By unique, I mean that some of the object's attributes might hold the same values as those of other objects, but they can't ALL be identical to another object's values. If I'm not mistaken, I can do this like so: class ...

refactoring and removing case statements when circling over an enum structure

Hello, An enum structure declared in its own class is a member variable to the business logic class. That enum basically represents the state of that other class. Although I have revisited the issue several times, replacing, or getting rid of those case statements proves quite frustrating to me. Several business logic methods simple i...

linking methods from an enum to member variables of client class

Hello, The following enum structure performs certain operations while remaining agnostic to the client class (for encapsulation reasons) public enum MyEnum implements Commands{ A{ public int method1(int varY) { return varY+2; } public MyEnum method2(){ return MyEnum.B; ...

Which one will be faster

Just calculating sum of two arrays with slight modification in code int main() { int a[10000]={0}; //initialize something int b[10000]={0}; //initialize something int sumA=0, sumB=0; for(int i=0; i<10000; i++) { sumA += a[i]; sumB += b[i]; } printf("%d %d",sumA,sumB); } OR int main() { ...

Wrapping Booleans in Objects

I have some code that I want to refactor. I have lots of methods that take multiple arguments of the same type, for example: public void foo(String name, String street, boolean b1, boolean b2) { ... } and so on. Because the different objects can only be distinguished by name I would like to wrap them in Objects (Enums) so I can make u...

Have you attempted a refactoring only to give up on it?

I recently attempted a large refactoring (yes I know smaller increments and unit testing along the way is preferred) that I just had to walk away from. It's not that I couldn't have done it, but I realized that the time to do it right wasn't justified in the business sense. Normally I am one to tackle refactoring with no fear because of ...

Hibernate - How to persist a new item in a Collection without loading the entire Collection

Hello - I ahve asked this on the Hibernate forums but no one seems to have been able to provide an answer so I am trying here! Thanks chaps! I have a collection in my model that contains a set of 'previous versions' of my root domain object. The previous versions are therefore 'immutable' and we will never want to update them, and only ...

Should I refactor my Django object model?

For reasons it's not worth getting into, the object Model of the django application I am working on is now "wrong" insofar as a number of relations that are 1 to Many are represented as Many to Many. The application functions correctly and is most of the way through QA. It has never been deployed. My design OCD makes me want to refact...