refactoring

Refactoring List<Foo> to FooList

I have a number of collections of classes which I need to refactor into new classes. I'm using Java with either Eclipse or Netbeans. Currently I create the new class FooList with a delegate List<Foo> and then follow all the places where the code fails to compile. Is there a way to do this without breaking the code (and preferably a singl...

How to (visual studio 2008 / Resharper) refactor / automate mixin pattern

Hi, I have Visual Studio 2008 with Resharper, does anyone know if there is any refactorings available that let you say create a class and use a member variable as a mixin? As a basic example, alot of the time you might want to implement a particular interface and use 95% of the underlying code of an already existing object (such as a ...

Refactoring: Gridview Export to CSV file

These routines (vb.net) allow you to dump a gridview to CSV, even if there are templated controls in the cells. It works, but I'm not thrilled with it. What improvements should I make and why? Private Shared Function CsvFormatted(ByVal t As String) As String If t.Contains(",") Then t = """" + t + """" End If Retu...

Refactoring a method which is calling others methods that throws Exception

I have several (more than 20) methods (getXXX()) that may throw an exception (a NotCalculatedException) when they are called. In another method, I need to access the results given by these methods. For the moment, I have an horrible code, which looks like: public void myMethod() { StringBuffer sb = new StringBuffer(); // Get 'f...

Coding Katas for practicing the refactoring of legacy code

I've gotten quite interested in coding katas in recent months. I believe they are a great way to hone my programming skills and improve the quality of the code I write on the job. There are numerous places where Katas can be found. like.. http://codekata.pragprog.com/ http://schuchert.wikispaces.com/Katas http://www.codingdojo.org/cg...

What is a good ratio of refactoring time versus development time?

Hello, I'm trying to build a plan on how we could spend more time refactoring. So I wanted to compare with the industry standards but I have hard time to find studies or metrics on that. I feel that 20% of dev time spent on refactoring seems a good ratio, but I don't have anything to show for it. In my mind, for 100% or dev time: 50%...

How to refactor long Front Controller?

I am using a Front Controller to send the user through a series of pages with questions. Pretty much everything must be dynamic as the pages, the questions, and everything else is set in the admin interface and stored in the database. I am tracking the user's progress through the database by storing a unique identifier in the session a...

How do you refactor JavaScript, HTML, CSS, etc?

I'm using Eclipse and the current solution (which I dislike) is to use "Search/Replace". This is an error prone solution. Do you know any better approach to refactor JavaScript, HTML, CSS resources safely in big applications? Or do you use any other cool refactoring tool(s)? ...

XAML Refactoring - How to extract common markup

I have some xaml pasted at the end of this question. It's from a resource file in my project. The HierarchicalDataTemplate and the DataTemplate share exactly the same structure. Is there a way to extract the common parts and reference it in? <HierarchicalDataTemplate DataType="{x:Type local:ChapterViewModel}" ...

Refactoring abstract Java class with many child classes

I'm looking for ideas on the best way to refactor this scenario (better design, minimal effort). Starting from the following example abstract class (actual has many more fields, methods and abstract methods) : abstract class Car { private int manufactureYear; // ... many more fields that are hard to clone public Car(int ma...

Remove unused references (!= usings) in C# project without Resharper?

Is there any way of removing unused references to assemblies, in a C# project, without the help of Resharper? The MSDN documentation does outline something for Visual Basic, but I couldn't find the same dialogs for C#. ...

Refactoring Linq to Sql

Is there a way to refactor linq to sql and take advantage of late evaluation? Is there a way to reuse object initilizer code? I have business objects that are persisted in a database and hydrated via a separate linq to sql layer. I would like to be able to reuse code from multiple queries that do the exact same thing. The portion of t...

Asp.net - Refactor action

Hi! I have this "problem" that i have code like this in many of my controller actions: var users = new List<SelectListItem>(); foreach(var user in userRepository.GetAll()) { var item = new SelectListItem { Text = user.FriendlyName, Value = user.UserId.ToString() }; if (User.Identity.Name == user.UserName) item.Selected = true; u...

Designing Constructors for Testability

I'm working with some existing code, trying to add to it and increase the unit tests for it. But running into some problems with getting the code testable. Original Constructor: public Info() throws Exception { _ServiceProperties = new ServiceProperties(); _SshProperties = new SshProperties(); } I'm aware that this is bad, and ob...

Are all Refactorings parameterized?

The question is about refactorings. Consider a rename method refactoring. This refactoring can be visualized as meta-method that takes old and new names, and changes the old method name to the new. so, for refactoring foo() { ......... ......... } to boo() { ......... ......... } the meta method for refactoring would be ... renam...

How to easy find unused public methods/properties

I have a .Net(C#) solution. The solution contains bunch of projects. The projects were implemented not by me. It is not a framework, it means that I need to have amount of public methods/properties as less as possible. My task is to identify methods and properties which are not used, but exist in the projects. Well, I can find private me...

C# code that generates javascript on the fly

Is it OK to generate code like this on the fly? Or is this a major code smell? How can this be made better? I'm new to web but I'm stumbling across this all the time and I don't really understand why. // Create a js function that applies foo to each group of controls foreach (KeyValuePair<string, Dictionary<Control, string>> pair in ...

How do I automatically clean up code in C++?

I'm working as a TA in an introductory programming class, and the students tend to submit their programs as either one line, or without any indentation. Is there any tool that allows me to insert indents and things like that automatically? (We're using C++ and VisualStudio) ...

Can we make this snippet groovier?

Hey, are there any improvements where i can improve this code? Maybe there are some groovy language features? This snippet flattens a xml file to: node/node/node def root = new XmlParser().parse("src/your_xml.xml") root.depthFirst().each { n -> def name = n.name() while(n?.parent()){ name = "${n?.parent()?.name()}/${name}"; n =...

Help me fix and refactor this calculator script in JavaScript / JQuery.

Hi guys, I decided to try and learn more JQuery and here is what I have come up with. It should be a simple enough job, but I can't get my head around it. I can add it up, but when I change a package, the price just keeps going up. I know I have to add some logic to decrement the counter, too, but I think a fresh pair of eyes would be...