refactoring

Refactoring val to method results in compile-time error

I currently have def list(node: NodeSeq): NodeSeq = { val all = Thing.findAll.flatMap({ thing => bind("thing", chooseTemplate("thing", "entry", node), "desc" -> Text(thing.desc.is), "creator" -> thing.creatorName.getOrElse("UNKNOWN"), "delete" -> SHtml.link("/test", () => delete(thing), Text("delete"...

"refactor refactor refactor your code." What does this mean exactly and why do it ?

I often heard from professionals blog something like refactoring your code whenever the chance you get. What is it exactly? Rewriting your code in simpler and fewer lines? What is the purpose of doing this? ...

Refactor packages in a Jar

I have a requirement that i need to load two versions of a jar at once. To avoid class path collisions I'd like to rename the packages of one of the jars. Then in source you could always easily determine the version by the package name. I've played with javap but couldn't find an assembler for Java 1.6. I've also attempted to decompi...

Help refactoring this nasty Ruby if/else statement

So I have this big, hairy if/else statement. I pass a tracking number to it, and then it determines what type of tracking number it is. How can I simplify this thing? Specifically wanting to reduce the number of lines of codes. if num_length < 8 tracking_service = false else if number[1, 1] == 'Z' tracking_service = 'ups' els...

Writing refactoring-friendly PHP code

As far as I know, and have gathered from other SO posts, there are no proper tools for refactoring PHP code yet, so when it comes to refactoring, it's probably good old search-and-replace for most of us, with a good amount of praying that we didn't overlook something. I would like to know whether there are any coding recommendations on...

How do I do distributed UML development (à la FOSS)?

I have a UML project (built in IBM's Rational System Architect/Modeler, so stored in their XML format) that has grown quite large. Additionally, it now contains several pieces that other groups would like to re-use. I come from a software development (especially FOSS) background, and am trying to understand how to use that as an analogy ...

Refactoring some of my code

I have a SalesOrder class which is inherited by several different types of sales orders. It has a method called ValidateItems(OrderItemList, itemAdditionalValidation), which takes in a list of order items and a delegate for additional validation on an order item. The different sales orders each define their own version of the delegate a...

Are empty abstract classes a bad practice, and why?

We have several empty abstract class in our codebase. I find that ugly. But besides this very stupid reason (ugliness), should I refactor it (into empty interface e.g.) ? Otherwise, the code is robust and well tested. So if it's only for a "aesthetic" reason, I will pass and let the empty abstract classes remain. What do you think? ED...

Recoding a Podcast Website - What should I use?

OK here is the deal. Me and some buddies are doing a Podcast(for over 4 year now) and in April we relaunched the site, that included a new Backend. Since I only had 2 weeks back then for getting everything to work, I decided to create something from scratch so everything fitted precisely our needs. The whole thing was written in Python b...

Java Null Conditional

I have the following pattern appearing many times in my Java code and was wondering how some of you might refactor it. Object obj1 = buildObj1(); if (obj1 != null) { return obj1; } Object obj2 = buildObj2(); if (obj2 != null) { return obj2; } Object obj3 = buildObj3(); if (obj3 != null) { return obj3; } ...

Error in Preview of Custom Eclipse refactoring

I am implementing an new eclipse refactoring. This will enable developers to Pull-up the preconditions statements from a child method to the parent method. This all works perfectly when I select "Finish" in the refactoring wizard, but when I select "Preview" I get an error "No target edit provided." This seems to be caused by a prob...

Does form processing code need to be abstracted? (Zend_Form)

In Zend Frameworks tutorials, I can see form processing code like if ($request->isPost()) { $formData = $request->getPost(); $code = $request->getParam("code"); $url = $request->getParam("url"); if ($form->isValid($formData)) { // here goes code to determine insert/update action...

How to avoid debugger-only variables?

I commonly place into variables values that are only used once after assignment. I do this to make debugging more convenient later, as I'm able to hover the value on the one line where it's later used. For example, this code doesn't let you hover the value of GetFoo(): return GetFoo(); But this code does: var foo = GetFoo(); return...

How would you refactor this bit of code?

This bit of code runs on Windows Compact Framework and what it does is obvious. It looks as it should be refactored (especially considering that I may want to add cmd.ExecuteResultSet() later), but I can't see an elegant way to do it. Any ideas appreciated. internal void RunNonQuery(string query) { string connString = Ge...

Using Exceptions exceptionally

Hi guys, This is a refactoring question. try { string line = GetFirstLineFromFile(); //Gets first line from a text file, this line would be a number. int value = ConvertToInteger(line); // Gets the integer value from the string. int result = DivideByValue(value); // Divides some number with the value retrieved. } catch(Exception ...

Refactoring function pointers to some form of templating

Bear with me as I dump the following simplified code: (I will describe the problem below.) class CMyClass { ... private: HRESULT ReadAlpha(PROPVARIANT* pPropVariant, SomeLib::Base *b); HRESULT ReadBeta(PROPVARIANT* pPropVariant, SomeLib::Base *b); typedef HRESULT (CMyClass::*ReadSignature)(PROPVARIANT* pPropVariant, SomeLib::Bas...

Dead code detection in PHP

I have a project with very messy code - lots of duplication and dead code here and there. Some time ago there was zero code coverage by unit-tests but now we're trying to write all new code in T.D.D. manner and lowering technical debt by covering "old" code by unit-tests as well(test-last technique). Business logic's complexity is quit...

How can I make this repeated code more elegant?

I have this repeated code below and I am assuming that this can be consolidated but if you notice each dictionary is different generic dictionary: dictionary1 is of type Dictionary<int, ContinuousIntegrationSolution> whereas dictionary2 is of type: Dictionary<int, BugTracker> DataTable dt = GetDataTable("CI"); for (...

How can this 6 line method be refactored to be more readable?

Hi everyone, I'm trying to clean up this ridonkulously ugly method here, that's crying out for refactoring, but I'm not sure what kind of structure would do this best (i.e. a case statement, or simply a carefully formatted if then statements) At first glance, it looks like it would be an ideal place for a case statement with a few well...

Distribute range in array

I need to create one array of numbers inside one range, like: [1..5] in 10 times = [1,1,2,2,3,3,4,4,5,5] [1..5] in 5 times = [1,2,3,4,5] [1..5] in 3 times = [1,3,5] def distribute(start_value, end_value, times, is_integer) array = Array.new(times-1) min_value = [end_value,start_value].min max_value = [end_value,start_...