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...
(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...
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
...
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,...
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...
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,
...
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, ...
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...
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...
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...
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':...
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...
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...
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...
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?
...
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 ...
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.
...
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...
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...
What are your .NET code-refactoring best practices?
...