refactoring

Refactored SQL projection?

I don't like having the same thing defined in two places, if I can avoid it. I realize the two queries below are dealing with two different tables, but those tables hold basically the same kind of data (distinct predicates warrant the two queries), and I think of the two projections below as "the same thing defined in two places". When...

Programming Language Properties that facilitate refactoring?

What are common traits/properties of programming languages that facilitate (simplify) the development of widely automated source code analysis and re-engineering (transformation) tools? I am mostly thinking in terms of programming language features that make it easier to develop static analysis and refactoring tools (i.e. compare Java v...

condense SQL in mySQL

How can I simplify this code in MySQL? SELECT name, MAX(IF(to_days(thedate) - to_days('2009-06-13') = 0, price, '')) AS date1, MAX(IF(to_days(thedate) - to_days('2009-06-13') = 1, price, '')) AS date2, MAX(IF(to_days(thedate) - to_days('2009-06-13') = 2, price, '')) AS date3, MAX(IF(to_days(thedate) - to_days('2009-06-13') = 3, ...

Splitting up a class into sub-classes

I've got a business logic layer class containing access methods for each table in a database. As there are quite a few tables now I'd like to restructure it to group the methods by entity (for easier access when coding). So, from this: BLL.Database MyDB = new BLL.Database(); BLL.Entity.User MyUser = Database.UserGetById(42); to this: ...

Daunting task of refactoring 5000 line CSS. Any tips?

I've just been assigned the task to refactor a huge 5000 line CSS file... but here's the worst part - I also need to make it IE6 compatible. Any CSS gurus have suggestions of tools, or possibly tips (common pitfalls) for use in my monolithic expedition? Cheers. ...

Python shortcuts

Python is filled with little neat shortcuts. For example: self.data = map(lambda x: list(x), data) and (although not so pretty) tuple(t[0] for t in self.result if t[0] != 'mysql' and t[0] != 'information_schema') among countless others. In the irc channel, they said "too many to know them all". I think we should list some here,...

Class library modification / migration

I have 3 class libraries. A BBL, a DAL, and a DATA (about 15 datasets). Currently 4 [major] applications utilize the functionality in these DLL's. I'm rewriting one of those applications and I need to (1) Use some of the existing functionality in the libraries (2) Change some of it (3) Add new functionality (4) Add new datasets. I'm bac...

Strongly typed calls into web.config without duplicating the property names?

I searched here for the answer. I'm sorry if this has been asked before (as I suspect it has). Summary: How can I have strongly typed calls into my web.config without duplicating the property names? Details: In my code, I try to minimize string usage, and I don't like defining something twice. Complementing both of these wonts is m...

Rename a class in Xcode: Refactor... is grayed out (disabled). Why?

Why is Refactor... grayed out (disabled) in Xcode? I'd like to rename a class. ...

Code reuse and refactoring

What's best practice for reuse of code versus copy/paste? The problem with reuse can be that changing the reused code will affect many other pieces of functionality. This is good & bad : good if the change is a bugfix or useful enhancement. Bad if other reusing code unexpectedly becomes broken because it relied on the old version (or t...

ListBox.DisplayMember = [String] Can I somehow workaround it to be other than string in .NET?

The question is asked with respect to an Object DataSource. So Consider that I have a class public class Customer{ public String name; public int age; public Customer(String name, int age) { this.name = name; this.age = age; } } And I have databound a list box to a list of these objects. So I say ...

Java: De-deprecated-ing Tools

Once a method is marked as deprecated, are there any tools which replace these methods with non-deprecated workarounds ? ...

Refactoring Really Seems to Have Vanished from my Xcode

I've read the similar (ok, almost identical) thread here as well as on the Apple iPhone Dev forums. I've looked carefullly at the referenced links. I have tried everything but nothing I do has brought refactoring back to life in XCode. Sigh. I took a working, 100% Cocoa Touch project (ie, Pragmatic Programmers - Coding in Objective-C 2....

Redunancy elimination in ASP.NET MVC Actions

Is this action too redundant - is there a better way to simplify it? [Authorize, AcceptVerbs(HttpVerbs.Post)] public ActionResult ChangePassword(string oldPassword, string newPassword, string confirmPassword) { var oldPasswordValidationResults = _validatorProvider.Validate<IStringLengthValidator>(oldPassword); oldPasswordValidat...

Do I need to test helper/setup methods?

So I have a helper method that looks something like the following: private D GetInstanceOfD(string param1, int param2) { A a = new A(); B a = new B(); C c = new C(a,b, param1); return new D(c, param2); } It's just a convenient helper method for which I can call to grab a particular object that I need rather then to re...

Would you have a factory for these methods. Static method on type or in factory?

Sorry for the bad title I just didn't know how to word it right. Say I have a class called Table and these three methods: //Creates a new table in underlying provider and returns new Table object. CreateNew(string Name); //Opens the table in provider and returns new Table object. OpenTable(string Path); //Same action as above just on ...

How much information hiding is necessary when doing code refactoring?

How much information hiding is necessary? I have boilerplate code before I delete a record, it looks like this: public override void OrderProcessing_Delete(Dictionary<string, object> pkColumns) { var c = Connect(); using (var cmd = new NpgsqlCommand("SELECT COUNT(*) FROM orders WHERE order_id = :_order_id", c)...

How can I make this LINQ query cleaner?

I have recently written a LINQ query to get a Dictionary containing the last 6 month's placement amounts. It is returning a Dictionary of Month string - Decimal Amount pairs. It seems kind of cludgey. Any of you LINQ masters out there able to help me refactor this to make a bit cleaner? /// <summary> /// Gets the last 6 months of Pla...

How to refactor usage of an iterator

I have some code i'd like to refactor that uses a C# iterator (ie IEnumerable). Unfortunately, I can't see to quite figure out the best way to allow other functions to work with the iterator without causing it to restart the iterator. For example: NewLineEnumerator nle = new NewLineEnumerator(); while (bytesRead > 0) { var nlenum =...

Can a test class become a "God object"?

I'm working on a backend for an open source Python ORM. The library includes a set of 450 test cases for each backend, all lumped into one giant test class. To me, that sounds like a lot for one class, but I've never worked on a project that has 450 test cases (I believe this library has ~2000 test cases not including the test cases fo...