refactoring

Searching asp.net Code

I want to search my asp.net pages and user controls to see which master page and base class they use. I mention search because we are re-factoring a large project and we need to track progress on the code conversion. I know I can pull this information individually but I need a automated and repeatable procedure. ...

Clean way to refactor test code

Background: I currently write test cases for the client side of a network protocol. As part of the tests I have to simulate several different expected and unexpected responses from the server (wrong header, connection lost, unexpected messages, timeouts). Each of these test-cases can be accessed by its unique address. My problem: The cur...

How to refactor this code?

Grouped params: <?php class Form { private $field; public function getFieldRelated($field) { return $this->fieldrelated[$field]; } public function __construct() { $this->fieldrelated['email']['name'] = 'email'; $this->fieldrelated['email']['value'] = $_POST['email']; $this->fieldrelated[...

Keeping a global reference to a control in WinForms for accessing GUI thread

(There's a tiny bit of history to this question, please bear with me) In this question, I talked about the possibility of centralising the 'cross thread' hocus-pocus that is required for updating the GUI like so: //Utility to avoid boiler-plate InvokeRequired code //Usage: SafeInvoker.Invoke(myCtrl, () => myCtrl.Enabled = false); publi...

Shortening a "Long" parameter list.

I'm refactoring one of my projects - a shopping cart. One of the tightly coupled areas of my code is the "Viewer" class - to generate information for the user to see, it often needs a combination of two or more of the following objects: The store catalog. The customer's order. The customer's mailing information. I can't really brea...

Design pattern to organize non-trivial ORM queries?

I am developing a web API with 10 tables or so in the backend, with several one-to-many and many-to-many associations. The API essentially is a database wrapper that performs validated updates and conditional queries. It's written in Python, and I use SQLAlchemy for ORM and CherryPy for HTTP handling. So far I have separated the 30-some...

What features do you look for (or use most) in refactoring tools?

I'm familiar with the basics, such as "Extract Method." But that is about all that I use. What others are there? This can include refactoring tool features and also macros that you write yourself. ...

Redirecting to same ActionResult from diffrent controllers

Hi all, I have a User entity, and in various views, I want to create links to a user home page basically. This fuctionality should be avaialbe in different controllers, so I can easily redirect to the user's home page. Each user in my site has a role ; for example reader, writer, editor, manager and admin. Ideally, I want to try to achi...

How to tighten up this Ruby code?

I'm wondering how I can write this better. I was trying to use inject instead of each, but kept running into errors. Mostly I'd like to tighten up the block. Any thoughts? def to_proc levels_of_nesting = @fields.zip(@orderings) procedure = nil levels_of_nesting.each do |field, ordering| procedure = proc_for(field, ...

What happens if I use "throw;" without an exception to throw?

Here's the setup. I have a C++ program which calls several functions, all of which potentially throw the same exception set, and I want the same behaviour for the exceptions in each function (e.g. print error message & reset all the data to the default for exceptionA; simply print for exceptionB; shut-down cleanly for all other exceptio...

PHP loading new models in a loop

I am currently battling this error message by refactoring some of my code: Fatal error: Allowed memory size of 33554432 bytes exhausted I figure I must have sloppy code somewhere. Is it a bad practice to load new models in a loop like so: <?php foreach($blog_ids as $blog_id) { $blog = new Blog($blog_id); echo $blog->titl...

Javascript refactor

Is there a better way to write this function? I've inherited some javascript code and I'd like to make this more concise if possible. Also, I'll probably be adding many more "theme" elements and don't want to copy and paste over and over. function imageClick() { var theme1 = document.getElementById("li-theme1"); var theme2 = documen...

Refactoring C++ code to use forward declarations

I've got a largeish codebase that's been around for a while and I'm trying to tidy it up a bit by refactoring it. One thing I'd like to do is find all the headers where I could forward declare members, instead of including the entire header file. This is a fairly labour intensive process and I'm looking for a tool that could help me fi...

How much duplicated code do you tolerate?

In a recent code review I spotted a few lines of duplicated logic in a class (less than 15 lines). When I suggested that the author refactor the code, he argued that the code is simpler to understand that way. After reading the code again, I have to agree extracting the duplicated logic would hurt readability a little. I know DRY is gu...

How to make this code more functional ?

Hi I am a newbie in functional programming. I just tried solving the following problem : [ a rough specification ] e.g.1: dividend : {3,5,9} divisor : {2,2} radix = 10 ans (remainder) : {7} Procedure : dividend = 3*10^2+5*10^1+9*10^0 = 359 similarly, divisor = 22 so 359 % 22 = 7 e.g.2: dividend : {555,555,555,555,555,555,555,555,55...

Refactor my ruby anagram solver?

I recently had to write an anagram solver for a job interview. Here is my code. class Anagram def self.resolves?(first_word, second_word) @letter_counts = {} # Assuming that anagrams aren't case sensitive. first_word.downcase! second_word.downcase! count_letters(first_word, 1) count_letters(second_word, -1)...

Shorter way to write this code?

I know how to make all these uiimageviews disappear and come back again, but I don't know how to write this shorter. They are all assigned unique tags 1-35. I want to check if ALL of them are hidden and then perform an action. if(test.hidden==YES && test2.hidden==YES && test3.hidden==YES && test4.hidden==YES ...

How/where to temporarily store ActiveRecord objects if not in session?

I'm refactoring a Rails-based event registration application that has a checkout process that hits several ActiveRecord models. Ideally, the objects should not be saved unless checkout is complete (payment is successfully processed). I'm not entirely certain why it would be a bad thing to serialize these objects into the session tempor...

Extract method to already existing interface with ReSharper

I'm adding a new method to a class that implements an interface, and I like to use the "Extract Interface" refactoring and just add the method to the interface. But it doesn't seem like ReSharper supports adding a method signature to an already existing interface. It feels like I'm missing something, I'm sure it can be done somehow. May...

implimenting refactoring setup as one-man team (PHP project)?

Hi folks, I had a web-based application outsourced (all PHP with jQuery and some other scripts and ajax). Now I am finished with the provider, and I'm slowly learning php and I'm wanting to begin refactoring this application so I can begin to more deeply understand it, and then begin adding more of the features I'm needing. I have seen...