refactoring

Java: Code Refactoring/Optimization

Please enlighten me: Which one do you prefer? Why? [Readability? Memory concern? Some other issues?] 1. String strSomething1 = someObject.getSomeProperties1(); strSomething1 = doSomeValidation(strSomething1); String strSomething2 = someObject.getSomeProperties2(); strSomething2 = doSomeValidation(strSomething2); String strSomeResult ...

Realign namespace definitions with file structure

Like all developers with OCD I try to organise my namespaces within our project so that they match where the file they are contained within sits of disk. However after a pretty massive refactoring session within VS.NET I've moved files within projects and created new subfolders a plenty, leaving the refactoring of the namespaces to late...

Multiple QMainWindow instances?

Hi all, The QMainWindow is the main window in a Qt application. So usually you'd have only one, but would it be possible at all to have multiple QMainWindow instances in your application? I am working on integrating a Qt-based GUI application B into another Qt-based GUI application A. Both these applications have a QMainWindow, and I ...

Refactoring "extreme" SQL queries

I have a business user who tried his hand at writing his own SQL query for a report of project statistics (e.g. number of tasks, milestones, etc.). The query starts off declaring a temp table of 80+ columns. There are then almost 70 UPDATE statements to the temp table over almost 500 lines of code that each contain their own little set o...

Replace Temp with Query

The Replace Temp with Query refactoring method is recommended quite widely now but seems to be very inefficient for very little gain. The method from the Martin Fowler's site gives the following example: Extract the expression into a method. Replace all references to the temp with the expression. The new method can then be used in ot...

How to find duplicate rows in a join text file

I have recently converted 10 JavaScript files into one file, which I then run a JavaScript compiler on. I just had a bug where I had reused a function name. Is there a tool to check for duplicate rows/function names in the combined file? Or should I create a little program? ...

Need help refactoring a simple jquery animation script

Hi I have a status message box (div box) positioned at the bottom of a web page using position: fixed; and bottom: 0;. Its height is initially 11px. I want to allow users to double click it when there are more status messages than what can fit within the default hight, make it grow. If they double click it again or move the mouse away ...

How to surround a code block with a using statement in ReSharper?

I'm watching Stephen A Bohlen's excellent Summer of NHibernate series, and have been watching him interact with CodeRush. I've recently installed ReSharper (I'm a ReSharper newbie), and I'm trying to find some of the ReSharper productivity equivalents that Stephen is demonstrating (tangentially) with CodeRush. As an example, he demonst...

How much logic should you put in the UI class?

I'm not sure if this has been asked or not yet, but how much logic should you put in your UI classes? When I started programming I used to put all my code behind events on the form which as everyone would know makes it an absolute pain in the butt to test and maintain. Overtime I have come to release how bad this practice is and have s...

Strategy for large scale refactoring

I'm currently working in a piece of code where both logic and data access are present in the GUI classes. Obviously, I would like to improve on this situation. The current current structure is basically: Big ball of mud The ultimate goal is to achieve a DDD-like structure: DAL Domain model Service layer Presentation model GUI So...

Refactoring a Hibernate entity into subclasses

I have a class that is currently mapped as an entity in a database table using Hibernate. This class should be refactored into an abstract class containing some field common to all of its subclasses. I'm using annotations for mapping hibernate entities/relationships classes. I would like suggestions/variants on how to do this refactori...

tool for detecting non-parametrized sql in java jdbc code

I'm looking to inspect SQL statements in Java/jdbc code to ensure that the SQL to be executed is of acceptable quality. Neither PMD not Findbugs appears to have JDBC or sql rules. I could use p6spy to log the SQL and look at that way, but this is manual. I'm wondering if the strategy of of using PMD/Findbugs/etc to create a rule that ...

Refactoring a massive function into many files.

I've been trying to refactor a "bit" of code that I'd previously developed. Basically, the project was my response to not knowing how to use XSLT effectively, so I developed an XML transformation system in PHP. The program reads through the tags of an XML file and does something along these lines to convert it to HTML: private function ...

C data structure to mimic C#'s List<List<int>>?

I am looking to refactor a c# method into a c function in an attempt to gain some speed, and then call the c dll in c# to allow my program to use the functionality. Currently the c# method takes a list of integers and returns a list of lists of integers. The method calculated the power set of the integers so an input of 3 ints would pr...

Best way to handle input and state changes for multiple states?

I have an application that has multiple states, with each state responding to input differently. The initial implementation was done with a big switch statement, which I refactored using the state pattern (at least, I think it's the state pattern. I'm kind of new to using design patterns, so I tend to get them confused) - class App { ...

How do I write message queue handling in an object-oriented way?

If you had to write code that takes messages from a message queue and updates a table in a database, how would you go about structuring it in a good oo way. How would you structure it? The messages is XML data, one node per row in the table. The rows in the table could be updated, deleted or inserted. ...

Refactor this nested IF function that is wrapped in a try/catch

Hi, I have a messy function that needs refactoring, it has too many nested IF's and it makes me nervous just to look at it! Please ignore what the functions are doing, I'm more concerned with the structure/flow and how it can be refactored so it has less nested IF statements The basic flow is as follows: public static void HandleUplo...

asp.net mvc related, mainly a refactor question.

can anyone think of a better way to do this? [AcceptVerbs(HttpVerbs.Post)] public ActionResult SaveAction() { NameValueDeserializer value = new NameValueDeserializer(); // selected messages MemberMessageSaveAction[] messages = (MemberMessageSaveAction[])value.Deserialize(Request.Form, "value", typeof(MemberMessageSaveAction[])...

Formatting a data structure into a comma-separated list of arguments

Hi, I need to convert a list (or a dict) into a comma-separated list for passing to another language. Is there a nicer way of doing this than: result = '' args = ['a', 'b', 'c', 'd'] i = 0 for arg in args: if i != 0: result += arg else: result += arg + ', ' i += 1 result = 'function (' + result + ') ...

Creating mdf file from sql script

I've created a database in Visual Studio 2008 in an App_Data folder of a MVC Web Application project. This results in an mdf file for the database that can be explored in the Server Explorer tab. You can create a SQL script for changes you do to the database. So I'm wondering how you run these sql change scripts to an mdf-file in Visual...