refactoring

Is it possible to refactor this Java code?

I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList { synchronized public Boid GetBoid( int idx_ ) throws ArrayIndexOutOfBoundsException { if( idx_ < super.size() && idx_ >= 0 ) { return (Boid) super.get(idx_); } else { throw new ArrayIndexOutOfBou...

How to refactor these 2 similar methods into one?

Hello, I've seen some samples of using 'T' to make a method reuseable for generic collections of different classes, but I've never really gotten into it or understood the samples. I wonder if it would be possible to put the 2 methods below into one and what the downsides of doing this would be (performance-wise). Anyone? ...

Why do we Refactor?

I would like to know the reasons that we do refactoring and justify it. I read a lot of people upset over the idea of refactoring. Refactoring was variously described as: A result of insufficient upfront design. Undisciplined hacking A dangerous activity that needlessly risked destabilizing working code A waste of resources. What are...

What's the best way to consume webservices in Classic ASP?

We have a three-tier architecture consisting of Classic ASP Frontend, VB COM+ Objects and MSSql Database. We are going to replace the VB COM by ASP.NET Webservice layer soon but we are not in the position to replace the Classic ASP with new .NET code (yet) and we're therefore going to need a way to consume webservices in Classic ASP... ...

Where can I find information on Authentication and Authorization in the context of Domain Driven Design ?

I'm trying to do things the DDD (domain driven design) way. And boy do I struggle. In all books I read, Authentication is of no concern and not mentioned! I've written my own Authentication and Membership Service which are responsible for registering and logging in users, creating salted passwords etc. I do not use .NET's Membership Pro...

What's a good practice for dividing up presenters in a MVP interface pattern that have grown to large?

One problem that I have frequently run into lately is the problem of my presenter classes growing too large. Usually, I can chop up a regular large class without skipping a beat. But the presenters sometimes are a little more difficult to pare down, without making the code harder to follow. Especially when the page starts filling up...

Is it worth refactoring Swing code to conform to coding standards?

Code generated for swing always fails when it comes to code quality. Inevitably, there's one method that builds the entire interface, and there's anonymous event handling code that calls member methods. Does anyone have some nuggets on transforming this monstrous code to well organized code. Is it worth going without a GUI builder too...

How would you refactor this smelly code? (Logging, Copy and Paste, .Net 3.5)

I've got code like this: Logger logger = new Logger(); System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); logger.LogInformation("Calling SomeObject.SomeMethod at " + DateTime.Now.ToString()); stopWatch.Start(); // This is the method I'm interested in. SomeResponse response = someObject.SomeMethod(someParam); st...

lots of boolean flag inputs to a class

I have a dialog that displays various things depending on state of the application, security for the current user etc. I am currently passing in several boolean flags and then enabling and/or hiding UI components depending on these flags.Eg: new MyDialog(showOptionsTable, allowFooInput, allowBarInput, isSuperUser) Initially this start...

Refactoring DAL Code to Support Stored Procedures (C#)

private static readonly string dataProvider = ConfigurationManager.AppSettings.Get("Provider"); private static readonly DbProviderFactory factory = DbProviderFactories.GetFactory(dataProvider); private static readonly string connectionString = ConfigurationManager.ConnectionStrings[dataProvider].ConnectionString; /// <sum...

In C# how many lines before a class should be consider to be refactored?

A good rule of thumb by is that I intelligently refactor any method over 50 lines. The count does not include comments and white space but actual code. The reason I also say intelligently is there are plenty of times where a class over 50 lines is acceptable and cannot or should not be changed. I do not have a rule of thumb for classe...

Where do I put dependency creation for a Presenter class in a Passive View architecture?

I've just refactored out a new domain class from a presenter class but I can't figure out where to instantiate it. This is part of a larger ongoing refactoring effort with a poorly maintained legacy project. The Presenter is currently being created by the view's OnLoad event and the view is passed as a parameter in the constructor. All...

Refactoring PostgreSQL SProcs

Hi, with a moderate PostgreSQL installation we accumulated quite a few stored procedures/functions and types. Now in the lowest level composite type (i.e. 3 types are built with it and a myriad functions reference any of those types) one element of the type is of wrong type (i.e. smallint instead of bigint), thus handling it is identi...

Ant exec refactoring

I've this code in my build.xml: <exec executable="cmd" osfamily="winnt"> <arg value="/c"/> <arg value="xsltproc\bin\xsltproc.exe"/> <arg value="--xinclude"/> <arg value="-o"/> <arg value="dist/html/main.html"/> <arg value="xsl/html/docbook.xsl"/> <arg value="xml/main.xml"/> ...

Best practices for developing refactor friendly code

Being a Java developer in an agile development cycle, I have learnt that it is essential to make sure I design my classes in a manner that I can refactor them easily without much of a pain. I want to know, what are the best practices that you follow in your daily design/development cycle that helps you to perform refactoring easily. For ...

Should one test internal implementation, or only test public behaviour?

Given software where ... The system consists of a few subsystems Each subsystem consists of a few components Each component is implemented using many classes ... I like to write automated tests of each subsystem or component. I don't write a test for each internal class of a component (except inasmuch as each class contributes to th...

How do I get Delphi 2009s (Refactor) Extract Interface to work?

I am trying to use Delphi 2009's refactoring to extract an interface from a class. The class looks something like this: Type TMyClass = class(TObject) private FPrivateVar: Integer; public procedure MyPublicProc(Value: String); function MyPublicFunc(Value: String): String; end; If I place the cursor in the public s...

Replacing all usages of a method (Introduce Indirection)

I am generally not very fond of refactoring tools. No need to get into details. Still, I occasionally try out new versions. Here is what I was trying to do while evaluating resharper 4.5 : I needed to replace all usages of a method with a wrapper method (to be created) but I could not. I usually suck at noticing an obvious feature, is t...

What refactoring tools do you use for .NET?

Do you use any of the refactoring tools like DevExpress' Refactor Pro? Which tool do you use and why? I'm looking for recommendations. Ideally I'd like open source tool that works with VB and C# inside VS2005 and VS2008. If I had to narrow down my list of ideals, I would purchase something for VS2008. Not sure on the language choice, pr...

What do you do with redundant code?

I have a class, which is part of a code library project that was written for a particular purpose that is no longer required. So the question is what do you do with code like this? Do you simply delete it, or do you leave it in bearing in mind that future developers may come across it and not realise that they can disregard it or do you ...