refactoring

Forking open source PHP code, project classloader strategy

I've been looking for a good PHP ORM tool to use, and I recently found a good ORM class in Kohana. It has a fairly good and simple ORM implementation. The problem is, the code is unreusable outside of the Kohana framework without a rewrite/refactor. It relies on the Kohana class loader and various framework loading strategies to even wor...

How does TDD make refactoring easier?

I've heard that projects developed using TDD are easier to refactor because the practice yields a comprehensive set of unit tests, which will (hopefully) fail if any change has broken the code. All of the examples I've seen of this, however, deal with refactoring implementation - changing an algorithm with a more efficient one, for examp...

Java: Out with the Old, In with the New ...

Java is nearing version 7. It occurs to me that there there must be plenty of textbooks and training manuals kicking around that teach methods based on older versions of Java; where the methods taught, would have far better solutions now. What are some boilerplate code situations, especially ones that you see people implement through fo...

When to call the gang of four? [When to use design patterns?]

In The Guerilla Guide to Interviewing Joel says that guys who want to get things done, but are not smart will do stupid things like using a visitor design pattern where a simple array would be sufficient. I find it hard to detect, if the design pattern suggested by the Gang of Four should be applied. Therefore, I would like some exampl...

Extensible rule-based pattern

I control access to some of my static web resources with some PHP logic. Because directory-based authorization through the webserver is not suitable or easily possible. A combination of things determines whether access is granted or denied. And these rules change from time to time. In the beginning it was a simple regex path match, a...

Loops in Makefile

I have a lot of assignments where I have to continually update a Makefile as I add more subsequently numbered C programs. Is there a way to do this with a loop which iterates over the values 1.1, 1.2, 1.3, etc.? all: 1.1 1.2 1.3 1.4 1.5 1.6 1.7. 1.8 1.9 1.1: 1.1.o gcc -o 1.1 $(FLAGS) 1.1.o 1.1.o: 1.1.c gcc -c $(FLAGS) 1.1.c 1...

Refactoring solution needed

Hi, I have a page on which I must load controls dynamically based on the user selection. Let's say that I have something like this: public static readonly Dictionary<string, string> DynamicControls = new Dictionary<string, string> { { "UserCtrl1", "~/Controls/UserCtrl1.ascx" }, { "UserCtrl2", "~/Control...

Truncate a string nicely to fit within a given pixel width.

Sometimes you have strings that must fit within a certain pixel width. This function attempts to do so efficiently. Please post your suggestions or refactorings below :) function fitStringToSize(str,len) { var shortStr = str; var f = document.createElement("span"); f.style.display = 'hidden'; f.style.padding = '0px'; ...

Using TryParse for Setting Object Property Values

I'm currently refactoring code to replace Convert.To's to TryParse. I've come across the following bit of code which is creating and assigning a property to an object. List<Person> list = new List<Person>(); foreach (DataRow row in dt.Rows) { var p = new Person{ RecordID = Convert.ToInt32(row["ContactID"]) }; list.Add(p); }...

Rewriting methods within a project

As a growing dev team we are beginning to encounter the problem of rewriting functions that behave in similar/identical ways. We are all guilty of failing to write documentation as time is a limiting factor, however the idea of gathering all current functions (duplicates and all) and using that list along with applied key words and the ...

Tool to refactor C# var to explicit type

Our coding standards ask that we minimise the use of C# var (suggests limiting it's use to being in conjunction with Linq). However there are times when using generics where it's reasonably convenient e.g. Dictionary<DateTime, Dictionary<string, float>> allValues = ... // ... foreach (var dateEntry in allValue) is easier to type for...

How to divide a large Java project into smaller components

We've trying to separate a big code base into logical modules. I would like some recommendations for tools as well as whatever experiences you might have had with this sort of thing. The application consists of a server WAR and several rich-clients distributed in JARs. The trouble is that it's all in one big, hairy code base, one sourc...

How fanatically do you eliminate Code Duplication?

How fanatic are you about elimination of duplicate code? Personally, whenever I see duplicate code, either in testing code or production, I tend to refactor the duplication away. The only exception I make are these: Sometimes the reduction in duplication is very minimal, because the newly refactored method have too many parameters to ...

Need for refactoring ?

Why should companies invest in refactoring components, though it is not going to add any new feature to the product ? I agree it is to clean the code, fix bugs and remove dead code - but what is the take ?? ...

Refactor menu item for VB.NET projects in VS2008

Is there any way to use the VS2008 built-in Refactoring functionality on VB.NET projects? ...

Is there any formal definition for "refactoring"?

Anyone knows a way to define refactoring in a more formal way? UPDATE. A refactoring is a pair R = (pre; T) where pre is the precondition that the program must satisfy, and T is the program transformation. ...

Refactoring for non OO languages

Can anyone recommend a website, book, or simply a list of refactoring strategies for procedural languages as opposed to object oriented languages? Everything I was able to find contained some strategies that could apply, most were useful only if working in an OO language. ...

JSON - Slashes and application type..refactoring

Hi My code works (yeah!) which sends json to a server.. would appreciate any thoughts on refactoring 1) My C# code sends this json to the server {\"firstName\":\"Bill\",\"lastName\":\"Gates\",\"email\":\"[email protected]\",\"deviceUUID\":\"abcdefghijklmnopqrstuvwxyz\"} Which I have to get rid of the slashes on the server side....not ...

Duck type as syntactic sugar for reflection: Good or bad idea?

I've been thinking lately, would it be a good form of syntactic sugar in languages like Java and C#, to include a "duck" type as a method parameter type? This would look as follows: void myFunction(duck foo) { foo.doStuff(); } This could be syntactic sugar for invoking doStuff() via reflection, or it could be implemented different...

Best strategy to get coding prepared for unit testing

I have a solution that is missing a lot of code coverage. I need to refactor this code to decouple to begin to create unit tests. What is the best strategy? I am first thinking that I should push to decouple business logic from data access from businessobjects to first get some organization and then drill down from there. Since many ...