refactoring

Which namespace does a factory class belong?

I have a factory class, DocumentLoaderFactory, which simply returns an instance that implements an interface, IDocumentLoader. All implementation resides under the following namespace Skim.Ssms.AddIn.ActiveFileExplorer.Loader But what I am wondering is, which namespace does DocumentLoaderFactory belong? I have placed the factory c...

css refactoring tool

i have taken over a website that has tons of css files and lots of inline css as well. Is there any tool that can show me a visualization of how this stuff is organized as i have a strong feeling that. Many pages are bringing in more css than necessary Also, i want to remove all the inline formatting as well into css files. Is there ...

Can this API be improved?

In our CORE library we offer this class as a 20,000 line abstraction. Can you see anything wrong with the way this is designed? Note1: This class has a SharpZipLib backing. Note2: SharpZipLib is approximately 20K lines. public static class Compression { public static Byte[] CompressBytes(Byte[] input); public static Byte[] C...

In your opinion what is more readable: ?? (operator) or use of if's

I have a method that will receive a string, but before I can work with it, I have to convert it to int. Sometimes it can be null and I have to change its value to "0". Today I have: public void doSomeWork(string value) { int SomeValue = int.Parse(value ?? "0"); //it can throw an exception(i know) } I did it, but my boss asked me t...

Code refactoring with python decorators?

Hi everyone, I'm actually struggling with some piece of code. I do know that it can be refactored, but I can't find the nice-smart-elegant solution. Here are two functions (much more functions of that kind are in my code): def fooA(param1, param2): if param2 == True: code_chunk_1 fooA_code #uses only param1 if pa...

How can I refactor this rails code - a key/value model

I have the following models: class FieldEntryValue < ActiveRecord::Base belongs_to :field_entry end and class FieldEntry < ActiveRecord::Base belongs_to :field belongs_to :media has_many :field_entry_values, :dependent => :destroy accepts_nested_attributes_for :field_entry_values, :allow_destroy => true end The FieldEntri...

How to make Databinding type safe and support refactoring

When I wish to bind a control to a property of my object, I have to provide the name of the property as a string. This is not very good because: If the property is removed or renamed, I don’t get a compiler warning. If a rename the property with a refactoring tool, it is likely the data binding will not be updated. I don’t get an er...

Can this JavaScript be optimized?

This JS will be executed on pages with a lot of fields. Can you see anyway to improve the speed of this code? If so, can you explain what you found? var _TextInputs = null; function GetTextInputs() { if (_TextInputs == null) { _TextInputs = jq('input[type=text]'); } return _TextInputs; } var _Spans = null; func...

How do you convince your manager that your project needs a huge refactoring?

I have joined a rails project as a contractor. The project has been going for more than a year. The code is written by about 10 different developers and most of them are contractors as well. They have different code style. Some of them came from Java. The code has horrible scores with metric_fu. Many functions are very long (100 - 300 li...

How to make this method non-recursive?

Hey. This example is pretty specific but I think it could apply to a broad range of functions. It's taken from some online programming contest. There is a game with a simple winning condition. Draw is not possible. Game cannot go on forever because every move takes you closer to the terminating condition. The function should, given a st...

Visual Basic 6 public variables to properties

Hello, i`m working on the legacy project in VB6 with huge object all with public variables. I want to convert these public variables to private variable/property combinations. Is there some tools with which i can do these conversion?(optimally all variables in class at once) Thanks ...

How can I separate SQL from my PHP?

Following Uncle Bob's avice in Clean Code, I'd like to have no SQL in my PHP code. Presently I'm making use of Prepared Statements and I've factored my database access code into model classes. My initial thought is to break out my SQL into separate SQL files and then load them at runtime. Since this involves more disk IO (my gut feeli...

Converting enum into a class hierarchy

Let's say I am writing a class in Cocoa to act as a proxy to a server. To represent the current state of the connection, consider the enumeration: enum { MyConnectionStatusDisconnected = 0, MyConnectionStatusConnecting, MyConnectionStatusConnected, MyConnectionStatusCount }; typedef NSUInteger MyConnectionStatus; I may...

Test -> Code -> Refactor, when should we start a refactoring?

The TDD circle is: "Write failing Test" -> "Write Code to fit a Test" -> "Refactor" At "Coding" step we are assumed to write code as simple as possible, just to fix a failing test. We should not write complex code until it is really required. The next step is Refactor. Should we refactor just written code? I think there is no real se...

Renaming packages in Eclipse

In Eclipse's "Package Explorer", let's say I have a list of packages like this: com.dog com.cat com.frog If I want to rename the "com" part of the package structure to be "animal", then I could select each package (above) and perform a refactor > rename. If I have many packages that start with "com", that process may take a while. ...

JPA reference refactoring

I refactor some classes from standard SQL to JPA/ORM usage. In most cases the Objects have a "real" reference but sometimes the references to other objects are only given by an unchecked database id reference (no foreign key, just simple a string with a reference to another table id). The code looks like: @Entity public final class my...

MS Access - Query Refactoring Assistance

I have a page in one of my client's websites that generates an extensive report pulling data from numerous tables throughout the website's MS Access database. One of the unfortunate architectural issues of the website is the existence of two nearly identical tables that represent the same "type" of data, but one is an "old" version and t...

What is the highest Cyclomatic Complexity of any function you maintain? And how would you go about refactoring it?

I was doing a little exploring of a legacy system I maintain, with NDepend (great tool check it out), the other day. My findings almost made me spray a mouthful of coffee all over my screen. The top 3 functions in this system ranked by descending cyclomatic complexity are: SomeAspNetGridControl.CreateChildControls (CC of 171!!!) SomeF...

Refactored methods and binary compatibility in Java

When refactoring methods it is easy to introduce binary incompabilities (with previous versions of the code) in Java. Consider changing a method to widen the type of its parameter to a parent interface: void doSomething(String x); // change it to void doSomething(CharSequence c); All the code that uses this method will continue...

Find redundant pages, files, stored procedures in legacy applications

I have several horrors of old ASP web applications. Does anyone have any easy ways to find what scripts, pages, and stored procedures are no longer needed? (besides the stuff in "old___code", "delete_this", etc ;-) ...