refactoring

Eclipse Extract Constant String from Existing Constant String

Say I've got an existing constant string: private final static String LOREM_IPSUM = "Lorem Ipsum"; Is there a way in Eclipse to quickly extract a substring of this as another constant such that I could end up with something like: private final static String LOREM = "Lorem"; private final static String IPSUM = "Ipsum"; private final s...

Best approach to refactor code to a newer version.

This question is related to my experience with FOSS as a student. Sorry I might be a bit subjective, but working with a certain approach here and would want to know if I am on the right track. I am involved in project,where I am supposed to refactor code which has been already written by someone else but was never included in the main t...

Tramp Data vs. Testability

I'm not doing much new development right now, but a lot of refactoring of older C# subsystems whose original requirements no longer support new and I'll add unexpected requirements. I'm also now using Rhino Mocks and unit tests where possible (vs 2008). The dilemma for me is that to make the methods testable and mockable, I need to defi...

rewrite small piece of python code

I have lots of small pieces of code that look like: for it in <iterable>: if <condition>: return True/False Is there a way I can rewrite this piece of code with a lambda expression ? I know I can factor it out in a small method/function, but I am looking for some lambda thing if it can be done. ...

Automatic refactoring tools?

Is there a tool that will scan your code and suggest which refactoring to perform, based on duplicate code segments that it finds? Let's say I'm specifically interested in C#/Java, but I'm open for tools in other languages as well. ...

How does Git track history during a refactoring ?

I understand well how Git can support file moves : as it uses file hash, a "added" file is easily detected as beeing same as the "removed" one. My question is about refactoring : considering Java, the package declaration changes so the file content will NOT be the same. In such case, how does Git determine that the "added" file shares h...

Visual Studio Refactor for vb.net

Hi. why visual Studio Does not have Refactor tool for vb.net by default ? but it has this tool for c#. for example extract method and etc. thanks all. ...

If db query A does not return enough results, run query B: how to optimize?

I am looking for a good design pattern, or best practice to achieve a situation of "either this query, or else that other query", with best performance and least overhead. Business logic/program of demans says "all items since Foo", unless that returns less then three items, then "all items". I am refactoring the current code, and can...

What is the cleanest way to extend this design for tree-rewriting?

I have a tree of objects, where each object has a std::vector of pointers to its children. The class of the object has a rewrite() method that is recursively applied to alter the object and its children, typically with the following transformations, where [N] is the object being rewritten and (M) is the element that rewrite() returns: ...

Error in liquibase table naming with hsqldb (in memory).Need a workaround

Hello Expert!! I'm using liquibase on a project and i just realize what makes my build fails.i've successfully use command line generateChangeLog against the same schema in mysql and included that file in my master-change-log file. For test environment i use hsqldb.Now all the table name are hyphen separated apart from language.Sinc...

How to refactor a class that is serialized in .NET?

I have a C# class that is serialized to disk by the BinaryFormatter, such as this example: // Version 3.0 [Serializable] public class Person { public string FullName; [OptionalField(VersionAdded=2)] public string NickName; [OptionalField(VersionAdded=2)] public DateTime BirthDate; [OptionalField(VersionAdded=3)...

type conversion for user defined classes

Hi, I have a lot of classes which are basically equivalent, ie have almost the same functions in all respect. Let's call them A and B. There are hundreds of methods that are using A and now due to code changes I have to change them to B. Is there a way by which I can program a mapping between A and B such that I have minimal code chan...

Refactor to take either NameValueCollection and KeyValueConfigurationCollection as parameter ?

Example code : EDITED : clarified example. Sorry for any confusion. using System.Collections.Specialized; using System.Configuration; ... // get collection 1 NameValueCollection c1 = ConfigurationManager.AppSettings; // get collection 2 ExeConfigurationFileMap map = new ExeConfi...

How to optimize/refactor such code?

In the current project, there are lots of GetData() method, which get different kind of data from hand written database at run time, and set them in different fields in a class. The projects then have such methods. void GetData(Datatype type, int& value); void GetData(Datatype type, double& value); void GetData(Datatype type, long& valu...

Refactoring advice and tools

I have some code that consists of a lot (several hundreds of LOC) of uggly conditionals i.e. SomeClass someClass = null; if("foo".equals(fooBar)) { // do something possibly involving more if-else statments // and possibly modify the someClass variable among others... } else if("bar".equals(fooBar)) { // Same as above but wi...

Can I DRY up these jQuery calls?

Is there a way to DRY this jQuery up? <script type="text/javascript"> $('form input#search').watermark('search...'); </script> <script type="text/javascript"> $('form input#post_title').watermark('title'); </script> <script type="text/javascript"> $('form input#post_tag_list').watermark('tag (separate tags with a comma)'); </scrip...

How can I abstract out a repeating try catch pattern in C++

I have a pattern that repeats for several member functions that looks like this: int myClass::abstract_one(int sig1) { try { return _original->abstract_one(sig1); } catch (std::exception& err) { handleException(err); } catch (...) { handleException(); } } bool myClass::abstract_two(int sig2) { try { return _or...

How should a size-limited stl-like container be implemented?

While refactoring, I wanted to change an array where entries are added to an std::vector, but for compatibility (persistency, downgrading,...), it still needs to have an upper limit. What is the best way (elegant, stl-like, limited extra code) to have an stl-like container which is limited in size, so you know that inserting an entry fai...

Refactoring a function definition

Hi, I am using Pydev on Eclipse to write python code. I am new to Pydev and to Eclipse. I love the feature where by I can use rightClick -> Refactoring -> Rename... to rename a variable. I was wondering if there is something similar to change a function everywhere in the project, if I change its definition. For example, suppose I ini...

refactor my if statement code

Hello, I've been messing with this bit of code for over an hour trying to rearrange it different ways. Is there any easier way to write it? if x is not Number ;// if x is string { if y is not Number ;// x, y both strings { Eval(x) Eval(y) return } else ...