refactoring

Using bash command line, how to add "import package.name.*;" to many java files?

I'm thinking of using find or grep to collect the files, and maybe sed to make the change, but what to do with the output? Or would it be better to use "argdo" in vim? Note: this question is asking for command line solutions, not IDE's. Answers and comments suggesting IDE's will be calmly, politely and serenely flagged. :-) ...

What is refactoring and what is only modifying code?

I know that refactoring is "changing the structure of a program so that the functionality is not changed". I was talking with some of the guys I'm working with on my final year project at university and I was surprised that they have a much more expansive (for want of a better word) view of refactoring. I consider refactoring to be thing...

In C# 3.5, How do you pass which method to call on an object as a parameter

I have two methods in C# 3.5 that are identical bar one function call, in the snippet below, see clientController.GetClientUsername vs clientController.GetClientGraphicalUsername private static bool TryGetLogonUserIdByUsername(IGetClientUsername clientController, string sClientId, out int? logonUserId) { string userna...

Rails Best Practices for Refactoring Dynamic Behavior

I have developed contingent country-state select dropdowns, and I'd like to factor out this behavior to an Address model so that I don't have to copy the dynamic behavior (more or less split between view and controller) each and every time I want the user to be able to enter a full address. Basically I'm trying to dip my toes a little d...

Java Reflection and the pain in Refactoring

Java Reflection provides a mechanism to introspect an Object at runtime. No second thoughts, this is a great feature, but it breaks all the Refactoring conventions! There is no easy way (other than File Search) even in modern IDE's to know which attribute is referenced and where. This makes Refactorings much more complex (tiresome!) and...

Tools for refactoring C# public fields into properties

I have a lot of C# code that uses public fields, and I would like to convert them to properties. I have Resharper, and it will do them one by one, but this will take forever. Does anyone know of an automated refactoring tool that can help with this? ...

Will "Working Effectively with Legacy Code" help someone working with an app ported from VB6 to VB.NET?

I would like to refactor a large legacy application originally written in VB6 and subsequently ported to .NET. In order to do this with confidence, I want to have unit tests around the existing code so I can compare before and after. What's the easiest and most effective way of doing this? There's a book called "Working Effectively wi...

MFC: OnInitialUpdate function of a CFormView-derived class

My CFormView-derived class is structured as follows: class FormViewClass : public CFormView { ... FormViewClass(); void Initialize(); virtual void OnInitialUpdate(); ... }; Ideally, I would like to call the Initialize() function in the body of the constructor as follows: FormViewClass::FormViewClass() { ...

How to overcome the anti-pattern "Big Ball of Mud"?

What causes a computer program to turn into a Big Ball of Mud? Is it possible to recover from this anti-pattern? Are there proven refactoring methods that can be applied? ...

Java Code Refactoring: Best beginner's books

Hi All, I am a java programmer. I recently have embarked on a refactoring project and so wanted to get some suggestions on any good books out there which can provide fast and practical insights for the same. I haven't done any refactoring projects before, and neither do I have much knowledge of design patterns yet, so some beginner leve...

How can I write a Visual Studio macro to perform an Extract Class refactoring?

I'm trying to build a macro for Visual Studio 2008 that behaves thusly: (Extract Class Macro) I highlight some text in the currently open document and call the Macro (using a keybinding or whatever). The macro runs "Project.AddClass" for the current active project, allowing me to specify the Class name. The macro adds the text I origi...

Replacement of Delphi IDE "Sync Edit" in Visual Studio

There is a feature in Delphi IDE (Borland Developer Studio 2006) which allows to edit some variable in "sync mode". For example if you have a code snippet like this: 2qdo8sz.png You can select the text you want to modify (in this case the complete procedure) and start editing a variable name. It will be edited at all the places (except ...

Assign Excel Range to a Javascript Array

I'm working on some code to export a DataTable to Excel, and I'm trying to make it as fast as possible. Right now, I'm looping through each row and each column for each row (nested for loops). When I've got a large DataTable, this process can take some time. Can I assign a range of cells to an array in Javascript instead of looping throu...

Testing for ImportErrors in Python

We're having a real problem with people checking in code that doesn't work because something's been refactored. Admittedly, this is partly because our developers don't really have any good tools for finding these kinds of mistakes easily. Are there any tools to help find ImportErrors in Python? Of course, the correct answer here is "y...

Non-member non-friend functions vs private functions

Herb Sutter has said that the most object oriented way to write methods in C++ is using non-member non-friend functions. Should that mean that I should take private methods and turn them into non-member non-friend functions? Any member variables that these methods may need can be passed in as parameters. Example (before): class Number ...

Is excessive use of this in C++ a code smell

I'm dealing with a large code base that uses the following construct throughout class MyClass { public: void f(int x); private: int x; }; void MyClass::f(int x) { ' ' this->x = x; ' ' } Personally, I'd always used and hence prefer the form class MyClass { public: void f(int x); private: int _x; }; void MyClass::f(int x)...

Dependency Injection in C++

How do I implement dependancy injection in C++ explicitly without using frameworks or reflection? I could use a factory to return a auto_ptr or a shared_ptr. Is this a good way to do it? ...

unit tests in C++

Is okay to break all dependencies using interfaces just to make a class testable? It involves significant overhead at runtime because of many virtual calls instead of plain method invocations. How does test driven development work in real world C++ applications? I read Working Effectively With Legacy Code and fond it quite useful but do...

Passing Files as Parameters

Hello. I have created an example to introduce my question. public class Algorithm { // This is the best, but circumstances prevent me from doing this. /*public static void computeSomething(Data data) { // Compute some stuff }*/ public static void computeSomething(DataFileReader reader) throws IOException {...

C#: How would you suggest to refactor these classes? (Interfaces, Aggregation or anything else)...

Having the following classes, in two different assemblies: class Member { public string Label {get;set;} // Lots of other fields... public double Thickness {get;set;} public double Width {get;set;} public double Length {get;set;} public double GetVolume () { return Thickness * Width * Length; } ...