refactoring

How to convert a PHP function to a non-function?

How can I convert the php function in the code below to a non-function. <?php require_once ('./mysqli_connect.php'); // Connect to the db. function make_list ($parent) { global $tasks; echo '<ol>'; foreach ($parent as $task_id => $todo) { echo "<li>$todo"; if (isset($tasks[$task_id])) { ...

Does any one know of any APEX refactoring tools?

The company that owns the company that I work for has recently decided unilaterally that the salesforce.com and force.com platform are where we are headed. Currently, we're a C# .NET shop and we frequently use Visual Studio and Resharper in our daily work. I'm not happy about this decision but, like any good developer, I'm willing to gi...

How to call overridden methods in a subclass? Potential candidate for refactoring

Originally I had a design problem where I needed five subclasses of a superclass, where all but two would use the same generic method of doing things and the other two classes would need special handling. I wanted to avoid writing the method five times; two special cases and three identical ones. So I had every class inherit SuperClass,...

C# - Casting an 'object' parameter into that object's type?

C# Hi all, I pass an object to a method. I want to cast that object to its specific class so I can perform its own specific methods? How can I do that? Move( new Cat() ); Move( new Pigeon() ); public void Move(object objectToMove) { if(objectToMove== Cat) { Cat catObject = objectToMove as Cat; catObject.Walk(...

How can I remove repeated code in my actions?

I have the following code repeated several times in a mvc app. public ActionResult AnAction(int Id) { var claim = GetClaim(Id); if (claim == null) { return View("ClaimNotFound"); } // do stuff here .... return ....; } So far this pattern is use...

'Remove middleman' IntelliJ refactoring on an empty interface

I have an interface which is now empty, and extends another interface. I'd like to remove the empty interface and use the base interface, and am trying to find the correct refactoring in IntelliJ. I've tried "remove middleman" but got "cannot perform the refactoring. The caret should be positioned at the name of the field to be refactor...

When Refactoring a project to improve maintainability, what are some of the things to target?

I've got a project (about 80K LOC) that I'm working on, and I've got nearly a full month of luxury refactoring and feature adding time prior to release so long as I'm careful not to break anything. With that being said, what can I do to improve maintainability. Please not there was no unit testing in place with this project and I'm not...

How can I improve this Comparator?

I've got a few Comparators -- one for Dates, one for decimals, one for percentages, etc. At first my decimal comparator looked like this: class NumericComparator implements Comparator<String> { @Override public int compare(String s1, String s2) { final Double i1 = Double.parseDouble(s1); final Double i2 = Double.parseDoubl...

Null pointers everywhere because data is suddenly sparse.

Someone designed code that relied on full data; the XML always had every element. The data source is now sending sparse XML; if it would have been empty before, it's missing now. So, it's time to refactor while fixing bugs. There's 100+ lines of code like this: functionDoSomething(foo, bar, getRoot().getChild("1").getChild("A"). ...

Optimising and Redesigning an existing Application

This seems to be a popular complaint on many programmer forums so I wouldn't be surprised if this question was already on here. Sorry if it has already been answered but I've searched and couldn't find one that relates to Java/OO. I have a somewhat complicated application that was written a number of months ago. It works well, but is sl...

How can I optimize this SQL query to get rid of the filesort and temp table?

Here's the query: SELECT count(id) AS count FROM `numbers` GROUP BY MONTH(created_at), YEAR(created_at) ORDER BY YEAR(created_at), MONTH(created_at) That query throws a 'Using temporary' and 'Using filesort' when doing EXPLAIN. Ultimately what I'm doing is looking at a table of user-submitted tracking numbers and co...

C# property refactoring - Should I care?

I have following code: public class Header { Line Lines { get { ...}} public ICryptographer GetCryptographer(FieldGroup group) { ... } } public class Line { public Header Header { get; set; } public FieldGroup FieldGroup { get; set; } ICryptographer CryptoGrapher { get { return Header.GetCryptogra...

Good open-source codebase for learning refactoring

What open-source codebases have you used to learn refactoring, written in either java or C# ? One requirement is good unit tests. ...

Refactoring function calls while reducing code duplication of resulting class definitions

I have a header file with about 400 function declarations and its corresponding source file with the definitions. In order to replace the implementation with a mock at runtime, I want to replace the implementation with calls to an object that will contain the implementation instead (pointer to implementation - pImpl). This means I will...

How to unify/simplify this code - event handling/delegating?

I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually a derived class) and a Graph Viewer (based on Microsoft Research's Automatic Graphing Layout). Each has a context menu which can have similar events activated. While the list view can have multiple selections, I don't allow it on th...

How to refactor this code?

Please suggest in refactoring this code. Avoid code duplication, mutiple If's public FormDataDTO getDataForFieldFormCHrzntalField(Field field) { FormDataDTO formDataDTO = new FormDataDTO(); CHrzntalField cHrzntalField = (CHrzntalField) field; for (int j = 0; j < cHrzntalField.getFieldCount(); j++) { Field sField = c...

Eclipse rename not working completely

Ok I'm completely googled-out. I have a few java projects in my eclipse workspace (about 25).   Most projects use linked source folders. When I rename a class in Project1, the references to that class in the other projects are not updated. The references within the project are updated just fine.   The net result is compilation errors...

Tools for C code refactoring

What tools are there that supports refactoring C code (renaming variables, extracting methods, finding method references, ...) Preferably for a Linux environment, but Windows tools are ok too. If there's something available for emacs, even better! ...

Is there a better way? While loops and continues

There are many functions within the code I am maintaining which have what could be described as boilerplate heavy. Here is the boilerplate pattern which is repeated ad nausea throughout the application when handling DB I/O with a cursor: if( !RowValue( row, m_InferredTable->YearColumn(), m_InferredTable->YearName(), m_InferredTable->Ta...

Migrate (monolithic) Classic ASP to ASP.Net

For many years I have had an objective of moving out of ASP/VBScript to a "better" language - my preference would be C# as I have skills in C - but I would consider other languages too (including PHP etc. so not just DotNet) Objective is to have the code base in a language which does more for us. I hate the lack of data typing in VBScri...