refactoring

Refactoring help...property-based object or lots of member fields?

I'm currently refactoring a class which currently looks something like this: class SomeModel { private String displayName; private int id; private boolean editable; private int minimumAllowedValue; private int maximumAllowedValue; private int value; // etc. etc.... a bunch (10+) of other fields... // an...

Tips on how to write refactoring-friendly unit TDD tests

Hi, I've been working on an ASP.NET MVC project for about 8 months now. For the most part I've been using TDD, some aspects were covered by unit tests only after I had written the actual code. In total the project pretty has good test coverage. I'm quite pleased with the results so far. Refactoring really is much easier and my tests h...

Smaller Methods

Following the guidelines given in "Clean Code" by Uncle Bob Martin, I'm trying to make my methods smaller. One recommendation he gives is that methods that contain a trys should invoke other methods that don't involve the exceptional cases. My problem is one of naming. Usually by the time my method only contains the try expression, th...

rate my code: on the spot interview with startup

1.5hr of coding in their smaller than by bedroom office with 4 desks lol. Afterward, while destressing at a bar, I refactored it a bit. objective was: develop a mechanism to define a schema for json objects and validate against it coerce data to schema types if possible, in case an int came in as a float or str develop mechanism to co...

Refactor Exception Handling

Ok i have sinned, i wrote too much code like this try { // my code } catch (Exception ex) { // doesn't matter } Now i'm going to cleanup/refactor this. I'm using NB 6.7 and code completion works fine on first writing, adding all Exception types, etc. Once i have done the above code NB do not give more help. Do you know a way t...

Refactor Ant scripts - multiple directories

I have a set of databases that are built using scripts that are run using ant. I have the scripts for each database in a separate directory. root (build.xml) - db1 (build.xml, *.sql) - db2 (build.xml, *.sql) ... The root build.xml has a target ... The build.xml in each of the subfolders is essentially the same but for the data...

How do I best combine and optimize these two queries?

Here is my main query which pulls in thread information as one row, it lacks the # of votes and currently I'm pulling that in with a second query. SELECT Group_concat(t.tag_name) AS `tags`, `p`.`thread_id`, `p`.`thread_name`, `p`.`thread_description`, `p`.`thread_owner_id`, `p`.`thread_view...

Approaching refactoring

I have a very data-centric application, written in Python / PyQt. I'm planning to do some refactoring to really separate the UI from the core, mainly because there aren't any real tests in place yet, and that clearly has to change. There is some separation already, and I think I've done quite a few things the right way, but it's far fro...

How do I share jQuery script between pages?

Hi folks, what is the best way to share jQuery code between pages? this is the situation: -------SITUATION--------- I have several different pages that goes this way (pseudo code) <% render "content/link" , collection => required_links %> In the "content/link" partial <div class="element_to_be_changed"/> Currently in EVERY PAGE...

Pimp my Perl code

I'm an experienced developer, but not in Perl. I usually learn Perl to hack a script, then I forget it again until the next time. Hence I'm looking for advice from the pros. This time around I'm building a series of data analysis scripts. Grossly simplified, the program structure is like this: 01 my $config_var = 999; 03 my $result_va...

Suggestions on How to Migrate Website from ASP.net 1.1/2.0 to 3.5

Good Morning All, I have inherited an ASP.net website that was originally started back in 2007. I believe that a lot of the codebase was written in version 1.1, patched to 2.0 where necessary. The client is still not happy with some features and has requested changes to be made. In "peeling back the onion skin" I found that the codeba...

Javascript to compare page you are on with a link

Hi folks, i have a menu, and i need the link for the current page i am on to be highlighted differently. I do a really twisted way of comparing strings now, but i am sure there is a smarter way? jQuery(document).ready (function(){ jQuery(".filteroptions .option").each (function (index,ele) { link=jQuer...

How to cope with bad code

One of the most unpleasant (and unfortuantely most frequent) situations I am confronted with in my all day life as a developer is that I have to fix bugs or add features into code that is badly designed. Now as a good craftsman I would like to leave the code in a better state than I found it. Often new features can not be implemented if ...

Method knows too much about methods it's calling

I have a method that I want to be "transactional" in the abstract sense. It calls two methods that happen to do stuff with the database, but this method doesn't know that. public void DoOperation() { using (var tx = new TransactionScope()) { Method1(); Method2(); tc.Complete(); } } public void Metho...

Simple refactoring example

Given the following code: public static bool UpdateUser(string userId, string jobTitle) { return GetProvider().UpdateUser (userId, jobTitle); } It needs to be changed and may not return a bool, for example: UserProfile userProfile = new UserProfile(); userProfile....

How to get Resharper to show a Refactoring that it already has.

Whenever Resharper encounters code like this: (treeListNode.Tag as GridLine).AdvertiserSeparation = 5; it presents you with a possible fix (since treeListNode.Tag as GridLine might be null). It says: 'Replace with Direct Cast', which turns the code into the following: ((GridLine) treeListNode.Tag).AdvertiserSeparation = 5; This is...

Reorganize Classes into Static Libraries

I am about to attempt reorganizing the way my group builds a set of large applications that share about 90% of their source files. Right now, these applications are built without any libraries whatsoever involved except for externally linked ones that are not under our control. The applications use the same common source files (we are ...

Cursor design and refactoring question

I have many cursors that all return rows with the same fields: a numeric ID field and an XMLType field. Every time I access one of these cursors (each cursor has now got its own function for access), I go through the same pattern: --query behind cursor is designed to no more than one row. for rec in c_someCursor(in_searchKey => local_se...

i violated D.R.Y. help me please?

I'm making a blackjack sim and I want to deal the cards how it would be in a casino, i.e. all players get dealt a card, dealer gets one face down, players get another card, dealer gets one face up BUT LOOK I VIOLATED DRY :( How to redo?? void BlackJack::newHand() { resetHands(); for (unsigned int i = 0; i < players.size(); i...

How to recognize that short code blocks can be refactored into something cleaner?

i have a bit of code that i wrote a few weeks ago (the code's purpose isn't so much important as its structure): if (_image.Empty) { //Use the true image size if they haven't specified a custom size if (_glyphSize.Width > 0) imageSize.Width = _glyphSize.Width //override else imageSize.Width = _image.GetWidth; if...