refactoring

What article discusses "Viewing code from 10000 feet"?

A few years ago I read an article about a neat way to analyze a large code-base. The idea was to zoom out so far that patterns of indentation and block length are all that is really visible. The author wrote about printing out code with very small fonts and looking at the results from 10 feet back. I believe the author also had some to...

how to survive maintaining a monster you created

You've worked somewhere for 3 years. At the beginning of the second year you were involved in what you thought would be a small project. You foolishly decided to take some risks with the choice of tools, you got slightly out of your depth, you ended up writing some nasty hacky code in the end as delays kicked in. The client loved it, y...

how to refactor this jQuery(only AJAX URL different)

function one(R) { # do some thing.. $.ajax({ 'url': '/one?search=' + R.val(), #some thing common here } function two(R) { # do some thing.. $.ajax({ 'url': '/two?search=' + R.val(), #some thing common here } well, since I'm just doing jQuery, but I guess this can get improve, refactor? ...

DRYing out C# for WPF windows with the same fields

I have two windows in my WPF app: a login window and an options window. Both have the same form with a user name and password field, as well as some other fields for providing credentials. I want some code that knows there will be a txt_userName TextBox available, for example, and can do things based on that. I was thinking I could m...

How do you go about refactoring the front-end of a large website?

I have a very large website that I need to refactor the front-end of due to maintainabilty concerns and performance issues: Whats tricky: Lots of overcomplicated scripts Over-complicated CSS with a whopping filesize No selenium tests in place No js tests in place Back end developers concerned anything breaking The site has been live f...

Auto-capitalizing all method names for port from Java to .NET

I am using IKVM to compile a large Java library project to a .NET DLL. In so doing, however, the method names are staying according to the Java convention of method names NOT being capitalized - but I want the .NET dll to be used in .NET projects and so would like the method names to be capitalized. The only exception would be methods w...

What's the most effective way to refactor this simple method?

I have implemented a very simple method: private String getProfileName(String path) { String testPath = null; for (int i = 0; i < path.length(); i++) { testPath = path.substring(0, i); if ( testPath.endsWith("1") || testPath.endsWith("2") || testPath.endsWith("3") || testPath.endsWith("4") || testPath.endsWith("...

How to avoid instanceof calls?

I defined this simple method: public static boolean isBorder(int x, int y) throws CollisionDetectionException { try { if ( (levelItems[x][y] instanceof StaticGameObject && levelItems[x][y].isVisible()) || (levelItems[x-1][y] instanceof StaticGameObject && levelItems[x-1][y].isVisible()) || ...

What is the cleanest way to duplicate base/parent.pm's functionality for non-object perl modules?

I'm not thinking too clearly right now and possibly overlooking something simple. I've been thinking about this for a while and been searching, but can't really think of any sensible search queries anymore that would lead me to what i seek. In short, I'm wondering how to do module inheritance, in the way base.pm/parent.pm do it for obje...

PMD code smell detection and refactoring

(I develop using JAVA and want to implement plugin in eclipse which can detect code smell and automate refactoring) 1) Initialy, I would like to find a smell detector library in order to get the smell existing in the class. I installed PMD plugin in Eclipse and try using it. I want to get all information which is represented in a views ...

Refactoring - which pattern to use in this example?

Hi, I have a function which is processing rows from an excel file.In this function,I have a for loop.Now,once a row is extracted,we check for various conditions.If any condition is false,we continue with next row.Can this code be made more structured using a pattern? foreach (System.Data.DataRow dr in ds.Tables[0].Rows) ...

Refactoring with dynamically typed language

Ok, I'm not trying to start a flame war here, and I know the argument between static and dynamic languages has been hashed out many times, including here. But I have a very practical question that hopefully someone here can shed some light on. Sorry for the length, but this is not a simple question with probably not a simple answer. Rub...

Java Generics Refactoring and Ambiguity

I have an old untyped class pre Java1.5 and need to refactor it using Java Generics to get more type security in the code. Old Code looks like this: class Foo { void setInput(Object input) {...} } Now this input could be some object but it may also be an array, nasty stuff. Making a generic version of it seems not to be trivial, I...

Building a long query and have a lot of if statements - is there a more elegant way?

I have to build a query based on certain conditions. Is there a better way of doing it than the way I have done below? It works fine but I can see it getting out of hand fairly quickly if there were more conditions since I check if any previous conditions had been met every time I check a new one. $sql = "SELECT DISTINCT fkRespond...

How can I refactor/extend the following model

I currently have a cache implementation (using arrays) for the heavy computations performed during the simulation. The structure of the cache is as follows: The way it works: CalculationsAbstract calculationsCache = new CalculationsCache(); // Constructor of CalculationsCache public CalculationsCache() { this.Proxy = new Calculat...

Refactoring library of eclipse

It is possible to implement the refactoring by using Eclipse library (JDT,LTK) without involving of the wizards. I would like to get benefit from refactoring feature of eclipse but I wan't to provide input for refactoring by other ways (that is not entering in the wizard) such as reading from file, etc. If possible , Please suggest me h...

Best way to deal with conflated business and presentation code?

Hi all, Considering a hypothetical situation where an old, legacy presentation library has been maintained over the years, and has gradually had more and more business logic coded into it through a process of hasty corrections and lack of proper architectural oversight. Alternatively, consider a business class or namespace that is not s...

How can I refactor this simple Ruby snippet?

I have a class that looks like this: class Base < Library prelude "some-value" # from Library def foo; ...; end prelude "some-other-value" # from Library def bar; ...; end # ... others end I'd like to refactor it into something like the following: class Base < Library # what goes here to bring FooSupport and Bar...

python reorganize codes

Sorry I dont know how to add a comment with the format, so I post another question with code here, as I am new to python, seems that there are many better ways to reorgnize the codes to make it better: def min_qvalue(self): s = 0 q = 1 for i in range(len(self.results)): if self.results[i].score > s: s = s...

How can I improve this long-winded Python code?

I have a data structure like this: items = [ ['Schools', '', '', '32'], ['Schools', 'Primary schools', '', '16'], ['Schools', 'Secondary schools', '', '16'], ['Schools', 'Secondary schools', 'Special ed', '8'], ['Schools', 'Secondary schools', 'Non-special ed', '8'], ] It's a list of spending items. Some are aggreg...