refactoring

How can I refactor this C# code using Split()?

How can I refactor this so that numberOfItems doesn't have to be declared as a variable? //method: gets the text in a string in front of a marker, if marker is not there, then return empty string //example: GetTextAfterMarker("documents/jan/letter043.doc","/") returns "letter043.doc" //example: GetTextAfterMarker("letter043.doc","/") re...

Open Sourcing a Framework: Ok, I bought the concept, now what?

(Note to moderators: I did my homework, and I know there is a very similar question, I'm putting on a different perspective. Please be somewhat more lenient to me. Yes, I'm asking for forgiveness not permission :]) In the past year, I wrote an application in order to deliver as my grad thesis. Its fine, and it works with some interestin...

PHP Refactoring Tools

I find it amazing how difficult it is to find a decent refactoring tool for PHP. What do you guys use (and how can I get it)? Thanks!! Edit: I'm on Linux but Windows suggestions would help the Googlers ...

How to refactor a class with overloaded constructors

I have a class with overloaded constructor (C#) It can be initialized in few ways, and some parameters are optional - so in result - there is a confusing bunch of constructors new Object(StrA, StrB, ObjA) new Object(StrA, StgB, ObjB, StrC) new Object(StrA, StrB, ObjA, StrD) new Object(StrA, StrB, ObjB, StrC, StrD) new Object(StrA, StrB,...

Better way to move NSView bounds with player?

Currently writing a roguelike to learn more about Objective-C/Cocoa. I'm really enjoying it so far and I've learned tons. This code moves the origin of the view's bounds, so that it follows the player as he moves. The code works perfect, I was just asking if there was a better way than using four for's. I've also seen in some cases th...

How to refactor this Python code?

class MainPage(webapp.RequestHandler): def get(self): user = users.get_current_user() tasks_query = Task.all() tasks = tasks_query.fetch(1000) if user: url = users.create_logout_url(self.request.uri) else: url = users.create_login_url(self.request.uri) template_values = { 'tasks': tasks, ...

What are some class names that would signal a need for refactoring?

I came across a few articles like this one, which suggest that some words should never be used as part of a class name. When a class has one of those words in the name, it means the code should be refactored or redesigned. Example: Manager Reason: Since almost all classes "manage" something and the meaning of "Manager" is very broad, ...

How to approach refactoring a class? (VB.Net)

I recently started a project and needed to do some integration with LDAP via DirectoryServices. I've done this in other apps so I went into one of them to see how I did it -- why reinvent the wheel right? Well, while this wheel works, it was developed years ago and kinda smells (it's wooden, firmly attached to the previous vehicle, har...

How do I create a Null Object in C#

Martin Fowler's Refactoring discusses creating Null Objects to avoid lots of if (myObject == null) tests. What is the right way to do this? My attempt violates the "virtual member call in constructor" rule. Here's my attempt at it: public class Animal { public virtual string Name { get; set; } public virtual...

Refactoring Derived Classes' Methods to Common Base Class' Method? (C#)

Hello, In my project I have a few functions in derived classes that are the same except for one section that is different in each. I want to pull the method up to the base class. The functions look like this: func(parameters) { //COMMON BITS if (someVar == "value1") { htmlFilename = line; } else if (someVar == "value2") { subV...

one liner for conditionally replacing dictionary values

Is there a better way to express this using list comprehension? Or any other way of expressing this in one line? I want to replace each value in the original dictionary with a corresponding value in the col dictionary, or leave it unchanged if its not in the col dictionary. col = {'1':3.5, '6':4.7} original = {'1':3, '2':1, '3':5, '4':...

Callbacks in ObjC+Cocoa

Hi, I'm relatively new to Cocoa/ObjC. Could someone please help me change my code to use asynchronous network calls? Currently it looks like this (fictional example): // Networker.m -(AttackResult*)attack:(Charactor*)target { // prepare attack information to be sent to server ServerData *data = ...; id resultData = [self se...

Refactoring Form to State Pattern?

I want to refactor some code. Basically the code I want to refactor is a Form (using System.Windows.Forms;) The way it is setup now, depending on which radio button you selected it shows a different layout for the window: different labels, buttons, etc. Not always a big difference, but different. This is a lot of conditional statemen...

Large Amounts of Setup Code: Does it indicate a problem and what stratergies exist to deal with it.

A part of my project interacts with iTunes using COM. The goal of the test in question is to verify that my object asks the iTunes API to export all of the album artwork for a collection of tracks to a file. I have successfully written a test which can prove my code is doing this, however to accomplish that I have had to stub out a chun...

Good examples when teaching refactoring?

I'm running a refactoring code dojo for some coworkers who asked how refactoring and patterns go together, and I need a sample code base. Anyone know of a good starting point that isn't to horrible they can't make heads or tails of the code, but can rewrite their way to something useful? ...

Refactoring C++ in Eclipse CDT

I've installed the Galileo release (Eclipse 3.5/CDT 5.1) in hopes of utilizing the better refactoring support mentioned in http://stackoverflow.com/questions/130913/what-is-the-state-of-c-refactor-support-in-eclipse However I do not see all the mentioned refactoring options listed. I don't see any plug-ins related to refactoring on ...

What is this RegEx statement doing?

I don't claim to be a RegEx guru at all, and I am a bit confused on what this statement is doing. I am trying to refactor and this is being called on a key press and eating a lot of CPU. Regex.Replace(_textBox.Text, "(?<!\r)\n", Environment.NewLine); Thanks. ...

How to find a mentor/code reviewer for freelancer?

About 6 moths ago I switched to fulltime freelance job. Before that I worked in enterprise environment with highly professional craftsmen :) I'm striving in improving my skills in Object Oriented Design and software architecture. I read lots of books about OOD, T.D.D., patterns(implementation, design, architectural). I like to research...

How can I make this massive Ruby if/elsif statement more compact and cleaner?

The following if/elsif statement is clearly a behemoth. The purpose of it is to change the phrasing of some text based on if certain data has been filled in by the user. I feel like there's got to be a better way to do this without taking up 30+ lines of code, but I'm just not sure how since I'm trying to customize the text pretty signif...

.NET Code refactorings, what is your best practice?

What are your .NET code-refactoring best practices? ...