Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.

learn more… | top users | synonyms (1)

0
votes
2answers
76 views

Can I refactor this method?

I wrote this method that does the job and passes the assertion tests for a large java backend project but I'm not all happy with the way it reads, perhaps you can tell me how to refactor and/or ...
1
vote
3answers
85 views

Make WCF Service testable

I have WCF Service. Its work fine and I want to have test coverage for it. Unit tests and acceptance. The problem is static class using in the code. How is it possible to avoid it? If it will ...
0
votes
0answers
38 views

Do these language descriptions have any obvious errors?

The esoteric Whitespace programming language has a few assembly languages that have been invented for it. My goal is to create various dialects for the same language in such a way that programs can be ...
0
votes
1answer
61 views

Refactoring this Android class in Tic-Tac-Toe

CellDrawableProvider is an Android class used in the game Tic-Tac-Toe. It provides drawables for cells of game board (drawables for figures X and O, and "Fire" if the cell is in the firing line). To ...
2
votes
1answer
58 views

Improving/shortening password checker

Can this be shortened/improved? I'm trying to make a password checker in Python. Could the ifs be put into a for loop? If so, how? pw = input("Enter password to test: ") caps = sum(1 for c in pw ...
4
votes
1answer
219 views

Will this code get me hired or laughed at? iOS MasterViewController

I plan on showing this project (only MasterViewController posted) during my interviews for an iOS developer position. Question: Will this code get me hired or laughed at? More Specifically: How ...
1
vote
1answer
52 views

Refactoring code for more readability

I've finally got all my code working as expected and it handles the data quickly. But now I'm looking to refactor it because there is some duplicate sections that just looks like can be broken down ...
1
vote
1answer
55 views

Refactoring a collection of if statements that contain 2 arguments.

At the moment I have seven if statements that resemble the following code: if(hit.collider.gameObject.tag == "Colour1" && start_time > look_at_time) { ...
3
votes
2answers
115 views

Making my program OOP

I have created a program that allows the user to view/add/delete employees and also view employee payslip either weekly employee or monthly employee and this is all done in the console. My programme ...
0
votes
1answer
70 views

First iOS App ViewController Refactoring Guidance

I'm relatively new to objective-c/iOS. This is my first meaningful app. My question is: How can I most effectively refactor the code in these 2 ViewControllers. I'm familiar with subclassing in ...
3
votes
0answers
48 views

How to refactor this series of JavaScript promises?

This is part of a class for paginating a Backbone collection. The paginateTo method is for paginating to a model id. It returns the model if it's already in the collection, otherwise it checks with ...
2
votes
2answers
188 views

Usage of lens for concise update of records

I'm new to Haskell. I'm developing a game-like simulation. I try to use lenses to update the state of the world. Current iteration of code works, but looks clumsy. I am trying to improve it, e.g. I ...
0
votes
1answer
83 views

Dynamically changing autocomplete source option jQuery

In this scenario I've got a textbox to which I have added autocomplete functionality. The kicker is that I want to dynamically change the source option of the AJAX call based on the value of a ...
3
votes
2answers
91 views

Optimizing code block using Switch Case

I have a implementation of following code block, public class FileFormatConversion { public static enum File_TYPES { PDF, PNG, OTHERS, ALL } public static void processOtherFileType(String arg1) ...
1
vote
1answer
65 views

Refactor similar queries but reverse side of inequality operator

How can I refactor this? public static IQueryable<T_COMPANY> WhereTotalTransactionOrShowCaseAtLeast(this IQueryable<T_COMPANY> query, int minimum, DateTime? date = null) { if (date == ...
2
votes
2answers
95 views

Code duplication where impliment extension method for IEnumerable and IQueryable on entity set

Since Entity Set does not support asqueryable, I have to do this. How can I reduce the amount of redundant code between the two methods? public static IQueryable<T> ...
1
vote
2answers
59 views

simple transaction process

I ask if the following code need some refactoring : public static int InsertBonus(DataTable dt, int month, int year) { int affectedRow = -1; using (IfxConnection con = new ...
4
votes
4answers
198 views

More Pythonic way to write this is_palindrome function?

from string import punctuation, ascii_lowercase def is_palindrome(string): """Return True if string is a palindrome, ignoring whitespaces and punctuation. """ new = "" for char in ...
3
votes
1answer
42 views

JavaScript/jQuery - How do I improve this js code/ refactor

I want to know how can I improve this piece of js with respect to best practices/performance. JS code: var treeGroupTypes, treeType, leftLeafClass, rightLeafClass; treeGroupTypes = ...
2
votes
2answers
57 views

Javascript card game, hand evaluation - review and suggest optimizations

So I have the following code (it looks long but it's not to bad): function evaluate_cards(hand){ var hand_length = hand.length; var num_of_sets = 0; var num_of_runs = 0; var ...
1
vote
1answer
53 views

How to optimize a custom function to scroll spy on the jScrollPane plugin?

Insight behind the code I have an element where the jScrollPane is being used to provide custom scrollbars for an extensive text. The idea behind the code below is change the image beside the text ...
3
votes
0answers
57 views

Refactoring my first python code to learn in deep

I'm beginner for python. Here is my first python demo code. I'm going to re factor this code step by step. any help would be very helpful to learn about python. Code description Batch program to ...
3
votes
2answers
74 views

Refactor Linq grouping

All of the class here share these same property Country, Total and Date. Total property are integer in some classes and decimal in some classed. The extension method below has a lot of duplication. ...
1
vote
3answers
40 views

Is my code unit testable

I've written a piece of code. Would like to know is the below piece of code unit testable or does it need any kind of refactoring. MatchCilentUrls is the primary method for matching two urls. Based ...
2
votes
2answers
66 views

How to optimize a function to get user quota stats?

I have the following function to collect quota information for the given user and return the information on a "ready to use" array: /* Get User Quota Information * * Prepare and array with the ...
2
votes
2answers
56 views

Recursive function refactoring help: occurrences of char in string starting at ith char

Just getting into functional programming and F# with the most appropriately titled Functional Programming Using F#. I wrote the following function definition for problem 2.4 but I'm thinking there's ...
2
votes
1answer
110 views

Is there any way to make this code shorter?

private void chckTable_CheckedChanged(object sender, EventArgs e) { DoAllCheckBoxesChecked(); } private void chckIndexs_CheckedChanged(object sender, EventArgs e) { DoAllCheckBoxesChecked(); } ...
4
votes
4answers
265 views

How to write this code without using 11 if-statements?

if (progressBar1.Value == 1) { progressLabel.Text = "1%"; } if (progressBar1.Value == 10) { progressLabel.Text = "10%"; } if (progressBar1.Value == 20) { progressLabel.Text = "20%"; } if ...
8
votes
6answers
338 views

Many if statements - refactoring

Yesterday I found some nice video from some IT conference about removing if statements from code. I saw a very nice example of refactoring. I am curious what do you think about it, especially what ...
5
votes
6answers
160 views

Long conditionals in ifs

Very easy question for these who spend some time on analyzing code written by co-workers. When I write my code, I do my best to write it in a very, extremely readable way. But sometimes I have an ...
0
votes
1answer
55 views

JavaScript binding loss with setTimeout

My current task is to extend some JavaScript of a framework we are using. A pop-up should slide in, instead of just appear in the middle of the window. So I have overridden one of the framework's ...
7
votes
2answers
140 views

Refactor code to populate a spreadsheet

My code looks ugly. What can you recommend? I already know about Enum; maybe it's a good variant for this situation. Anything else? private void writerContent(Integer firstRow, List<Record> ...
3
votes
1answer
39 views

Refactoring my windowsFormApp code

I have around 150 lines of code that I managed to optimize. But, because my two methods and the six if-statements almost are identical, could there be room for improvement? Maybe it could be done ...
1
vote
2answers
70 views

Rails 3 nested controller method

I have 2 nested resources in one of my Rails apps and the way the index is handled by the inner resources bothers me somewhat: def index @program = Program.approved.find(params[:program_id]) if ...
0
votes
1answer
29 views

Creating a generic function for objects of different classes

How might I refactor this to get rid of all the if-else? def self.dispatches_for(object) scope = Dispatch.asc(:days) if object.class == Habit scope.where(:habit=>object).map{|d|d} ...
0
votes
0answers
15 views

How can I reduce redundancy in this angular or the angular html?

I'm very new to angular as far as directive and module options. I've just made my first module and factory here. The areas in the UL are frequently repeated elsewhere in the app, but are seem like ...
0
votes
2answers
91 views

Refactoring implementation in.NET

I have implemented the following code: class A { abstract void f1(Object obj, Object data); } class A1:A { void f1(Object obj, Object data) { m1(obj,data); } void ...
3
votes
1answer
73 views

State Machine for Character

I come today with a state machine I'm currently working on. Problem: Given any State that the Character is in, a button press or combination of button presses can modify that state in a different ...
2
votes
1answer
59 views

Python: refactoring verbose functions

I wrote up a simple averages calculator for student grades, based on this daily programming challenge. First, the script asks for the file name for the text file containing the student names and ...
1
vote
1answer
122 views

What about accessing jQuery plugin methods with triggers?

There is my jQuery Color Picker Sliders plugin you can access on jsFiddle: http://jsfiddle.net/styu/5H8cA/ I want to access some of the methods from outside of the plugins scope, namely showPopup(), ...
1
vote
2answers
107 views

How to further refactor these ruby methods?

The code I'm trying to improve, modifies a url according to the options passed in a hash, like this: { :image_aspect_ratio => "square", :image_size => 50 } or { :image_size => { ...
1
vote
2answers
62 views

Write a class with some properties and indexed

Is there a better way to write it? I need the best way to write it. It is this principle? Please show me a better way it breaks SRP? public class PlacementLocation { public int Row { get; set; ...
2
votes
1answer
150 views

Refactoring to avoid if-else in numberOfRowsInSection and cellForRowAtIndexPath

Below is the code that I would like to refactor in order to avoid if-else statements in cellForRowAtIndexPath and numberOfRowsInSection. Depending upon what user selects, section order and ...
2
votes
1answer
63 views

Review internet connection pinging method

This is some C code I have to simply test the internet connection. Any comments/tips on efficiency and refactoring this program down would be greatly appreciated. int testConnection(void) { int ...
2
votes
3answers
108 views

Did I Needlessly Complicate This Function?

Background: We're using a class called Places (inspired by Allen Holub's great article on DrDobbs) that resolved our program paths based on the existence of a configuration file, environment variable ...
4
votes
2answers
136 views

Is there a way to refactor this code?

I'm new to ruby on rails, on this project I'm using Ruby 2.0 and Ruby on Rails 3.0. I would like to know if this piece of code can be refactored, as it is unless params["ot_code"].nil? ots ...
2
votes
1answer
62 views

Different types of model validation

So we have a RESTful webservice that implements CRUD operations for a model, like this one: class MyModel { private long id; private String name; // other fields private boolean ...
2
votes
1answer
111 views

What is the point of this code?

I have come across below method and as far as I can see this method just converts the first letter of a String to uppercase in if its not already. Below main method returns : "Joe" "Joe" "Jo..E" ...
4
votes
2answers
135 views

Small function and level of abstraction - clean code - refactor further

In the book Clean Code from Robert C. Martin are given many recommendations. Two of them are to keep functions small and within a function to only have one level of abstraction. I already ...
1
vote
1answer
73 views

Lowering the cyclomatic complexity of this method, suggestions?

The PHP Mess Detector of my IDE warns about a Cyclomatic Complexity of 14 (threshold is 10). To me this code doesn't seem to hard to follow. Would you refactor it in some way to lower the metric? ...