refactoring

Erlang: simple refactoring

Consider the code: f(command1, UserId) -> case is_registered(UserId) of true -> %% do command1 ok; false -> not_registered end; f(command2, UserId) -> case is_registered(UserId) of true -> %% do command2 ok; false -> not_...

Ruby non_empty? method

I want to use expression: !([1,2,3] & [43,5]).empty? => false !([1,2,3] & [3,5]).empty? => true to check if two arrays contains at least one common value. And I wonder if there is a better way of doing it? Maybe something like: ([1,2,3] & [3,5]).non_empty? How to write non_empty? method? ...

Retrieving all objects in code upfront for performance reasons

How do you folks retrieve all objects in code upfront? I figure you can increase performance if you bundle all the model calls together? This makes for a bigger deal, especially if your DB cannot keep everything in memory def hitDBSeperately { get X users ...code get Y users... code get Z users... code } ...

How to refactor my class so I can unit test it?

I am trying to unit test a class that does SAX parsing and creates an object. This class takes a string as a parameter representing the URL of a document on the internet, parses it and then creates an object based on the contents. I don't want to have the unit tests actually access the network, so I'd like to have a few test xml files t...

Replicating object function across various model files in Ruby on Rails

I am looking to replicate a given object function across various model files As you can see below, the 2 things I need to vary across the model are 1) the "guser" string 2) the self.xxx SIMPLIFIED CODE SAMPLE: def self.get_all statement="SELECT * FROM gusers WHERE" results = results + self.find_by_sql(["#{statement...

VC++ addon that renames the file along with the class

I'm using VisualAssistX for some refactoring tasks in VC++2008. When I autorename a class, I want the filename to also be updated automatically. Any addon that does that? (Yes, I do only put one class per cpp/h pair) ...

When to delete newly deprecated code?

I spent a month writing an elaborate payment system that handles both credit card payments and electronic fund transfers. My work was used on production server for about a month. I was told recently by the client that he no longer wants to use the electronic fund transfer feature. Because the way I had to interface and communicate wit...

Rails- Using a set of functions across the view , controller and model

Hi folks, i have a function that converts an array to a hash which i would like to use across all the model, controller and view files in the rails app. Does this violate some core design principle, or am i missing something really obvious? UPDATE: This is actually a software engineering question. I want to understand why some "conveni...

How do I convert a local variable in a method to a method parameter using eclipse refactor?

How do I convert a local variable in a method to a method parameter using eclipse refactor? ...

Organizing Eager Queries in an ObjectContext

I am messing around with Entity Framework 3.5 SP1 and I am trying to find a cleaner way to do the below. I have an EF model and I am adding some Eager Loaded entities and i want them all to reside in the "Eager" property in the context. We originally were just changing the entity set name, but it seems a lot cleaner to just use a pr...

How easy would it be to refactor a small JSP/Servlet/JDBC project to SpringMVC/Hibernate

With reference to this post, I am considering starting a new web-based Java project. Since I don't know Spring/Hibernate I was concerned if it's a bad plan to start learning them while creating a new project, especially since it will slow down the early development. One idea I had was to write a prototype using tech I do know, namely JS...

Tool that shows unit dependencies for Delphi 2010 or Delphi 7 program

We're trying to untangle a hairball of 100's of units, removing some. It would be helpful if there was tool that would show us what units were explicitly using unit X. Penganza doesn't seem to have a report that does that. (Although it has lots of other useful reports.) Can anyone suggest a tool or strategy for doing this, other than ...

Flexibility starting to develop applications and DB

Hi! First of all I want to say some info for admins. This post can help to all DBA and developers. Hope You don't close this. I'm writing about widespread problem I'm writing master work and I want that You will had little time to answer my questions in my form. These questions are about db structures. Visit here: http://spreadsheets.g...

How to take advantage of an auto-property when refactoring this .Net 1.1 sample?

I see a lot of legacy .Net 1.1-style code at work like in example below, which I would like to shrink with the help of an auto-property. This will help many classes shrink by 30-40%, which I think would be good. public int MyIntThingy { get { return _myIntThingy; } set { _myIntThingy = value; } ...

How do I correct feature envy in this case?

I have some code that looks like: class Parent { private Intermediate intermediateContainer; public Intermediate getIntermediate(); } class Intermediate { private Child child; public Child getChild() {...} public void intermediateOp(); } class Child { public void something(); public void somethingElse(); } class Client { priv...

Better name needed for applying a function on elements of a container

I have a container class (containing a multi-index container) for which I have a public "foreach" member-function, so users can pass a functor to apply on all elements. While implementing, I had a case where the functor should only be applied to some elements of a range in the container, so I overloaded the foreach, to pass some valid ra...

Refactoring if/else logic

I have a java class with a thousand line method of if/else logic like this: if (userType == "admin") { if (age > 12) { if (location == "USA") { // do stuff } else if (location == "Mexico") { // do something slightly different than the US case } } else if (age < 12 && ...

Program structure in long running data processing python script

For my current job I am writing some long-running (think hours to days) scripts that do CPU intensive data-processing. The program flow is very simple - it proceeds into the main loop, completes the main loop, saves output and terminates: The basic structure of my programs tends to be like so: <import statements> <constant declaration...

Tool for sql refactoring?

Is there a refactoring tool available for SQL (TSQL in particular). Is there any tool that can do automatic simplification of SQL? I have a set of views where only the top two are used, and I'd like to refactor this into only two views, hence 10+ queries into two queries. ...

Throws declarations and interface methods

Here's some code from an FTP application I'm working on. The first method comes from an interface which is being triggered by a class which is monitoring server output. @Override public void responseReceived(FTPServerResponse event) { if (event.getFtpResponseCode() == 227) { try { setupPassiveConnection(event.get...