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)

1
vote
0answers
16 views

Circular Buffer on a typed Float32Array

I'd like , if you would be so kind, some suggestions on performance improvement or maybe someone can point out mistakes I made in the implementation. I am sure there are better ways to do things but ...
0
votes
1answer
32 views

How Can I Refactor This Code For Input Errors

I'd like to refactor the code below to account for if someone types in something besides a number 1 thru 5 or a comma. def roll_again puts "Which dice would you like to keep from this roll? (1, 2, ...
1
vote
1answer
42 views

Refactoring tips

I don't really have experience in factoring. My code is really long, i don't use functions because i don't know if it needs to be a function. I hope you could give me tips so i could clean up my code. ...
0
votes
0answers
15 views

Using a spinner like a HTML select to display string but return int value

I'm still learning Android, I need to have a spinner and for it to display a list of string values. However, when I submit that data later on I need a corresponding integer value. Similarly to how a ...
0
votes
0answers
31 views

How Can I Refactor the Yahtzee Program I Built in Ruby

require'yaml' require 'text-table' class Yahtzee def initialize puts "Welcome to Yahtzee, please enter your name." @name = gets.chomp @turn = 0 @scorecard = {"aces" => 0, "twos" ...
2
votes
2answers
44 views

Separate Numbers with Commas in Ruby

Help! My code works, but it is ugly!! As a newbie, how should I approach refactoring this code? def separate_comma(number) a = number.to_s.split('') b = a.size/3.0 if a.size < 4 p ...
2
votes
5answers
135 views

Java, which of these two is better? [on hold]

SomeClass obj = null; try { doSomething(); obj = getResult(); } catch (Exception e) { e.printStackTrace(); } return obj; or try { doSomething(); return getResult(); } catch ...
0
votes
1answer
28 views

How should I refactor my image uploader script?

I come from a C background and need help refactoring the following imgur image uploader script I wrote. It checks if a token_file with access_token and refresh_token exists. If not, it instructs the ...
2
votes
2answers
73 views

Refactoring same loop logic with different input data

I have these two methods: public static String buildLine(String[] values) { StringBuilder lineBuilder = new StringBuilder(); for (int i = 0; i < values.length - 1; i++) { ...
3
votes
1answer
62 views

Refactoring a method that binds data to a TreeView

All the flow depends on parameters. It's all in same method with an if else...but I want to make the code a bit more clear. How can I functionally decompose this method into many? private void ...
0
votes
2answers
66 views

Printing out all the subsets of a set. Am I unnecessarily creating new objects?

1) I am concerned about the creating too many objects in my code. 2) Am I using duplicate code? Can I cut down on the number of lines of code? Note: I only want to use recursion to solve this. ...
0
votes
2answers
47 views

Refactor selective item by highest create date or update date

I have to check for the Highest Date from CostRepository whether it is create date or edit date then i have to get value in that field. edit date can be null. i don't know how to fix the codesmell. ...
1
vote
2answers
60 views

Refactor data tranfer object and model

T_PROJECT is the class that will be retrieve data from linq to sql and ProjectOwnerDataFields is the class that will be used to show data in view. in edit mode i have to get value from model and send ...
1
vote
1answer
44 views

Refactor LINQ & XML code

I have some duplicate code using LINQ & XML. I'm sure there is a way to refactor it, but I'm not sure how to go about doing it. Would someone help, please? var fileInfo = ...
1
vote
1answer
29 views

Refactor LINQ & XML code [duplicate]

I have some duplicate code using LINQ & XML. I'm sure there is a way to refactor it, but I'm not sure how to go about doing it. Would someone help, please? var fileInfo = ...
2
votes
1answer
74 views

Refactor Linq Expression

Is there any way I can refactor this expression tree? public static IOrderedQueryable<T_PO> SortedPO(this IQueryable<T_PO> query, ExtjsGridPagingParameter.SortingParameter ...
1
vote
3answers
122 views

Refactoring from if-else-if to Dictionary

I have come across the following piece of code if (Region.Current == Region.EU) { return RegionalPriceLN; } else if (Region.Current == Region.NY) { return ...
6
votes
2answers
209 views

Chess board representation in Java

I'm currently working on a small chess game written in Java. The board is modeled as a Board object with a 2D array of Piece objects : public class Board { private final int ROWS = 8; private ...
4
votes
3answers
119 views

refactor Python code with lots of None type checks

When I wrote this it just felt messy due to the null checks. Any good ideas on how to clean it up would be most appreciated. def getItemsInStock(self): itemsInStock = [] items = ...
9
votes
5answers
1k views

Repetitive code driving me crazy!

Ok, So first I must say that everything I know about coding I have learned on my own in my spare time so bear with me if my code is primitive, but please, I am open to any comments to make me ...
0
votes
1answer
80 views

Review my PuzzlesView android component

Began to read the book "Clean Code" by Robert Martin, I had a strong desire to learn how to write code that easy to understand other people. Please criticize my code. PuzzlesView.java // Using of ...
0
votes
0answers
50 views

Button clicks to add GridViews inside TabContainer, Refactoring

I have a program which is primarily illustrative in example to help me learn refactoring techniques and best practices. This program will take the ActiveTabIndex property of a TabContainer control ...
0
votes
1answer
26 views

How to refactor complex dashboard using presenters and/or service objects

TL;DR I need a way to refactor a complex user dashboard with several objects and some complex data to display a accounting chart. I have read about both presenters (also called decorators or view ...
2
votes
3answers
97 views

Tips to refactor code : very repetitive code

I have this very simple problem : my code is too repetitive. It works, but it could be much cleaner. I don't know exactly where to start. I'd like to learn to work better, and I'd really like ...
1
vote
2answers
71 views

Refactoring in Python

I am trying to learn some re factoring techniques on my own and wanted a few exmaples. I am given the following code: import csv from xml.etree.ElementTree import Element, SubElement, Comment, ...
0
votes
0answers
29 views

Refactoring In Python [duplicate]

I am trying to learn some re factoring techniques on my own and wanted a few exmaples. I am given the following code: import csv from xml.etree.ElementTree import Element, SubElement, Comment, ...
1
vote
1answer
78 views

refactoring and optimization the class

There is repetition here and would appreciate help in improving this code. Suggestions? Here's the framework for it: Class Author { private Integer id; public static List<Book> ...
4
votes
1answer
132 views

How can I refactor my Controller Action to not be so complex?

I'm building a website that is used to search our system. The users can search on a lot of critera at once. As I try to do this though, I can't figure out how to simplify this horrible action. ...
0
votes
1answer
66 views

Quick and dirty command line application in Ruby. Now it's time to refactor, where should I start?

#!/usr/bin/env ruby require 'pivotal-tracker' require 'yaml' TEMP_DIR = "#{ENV['HOME']}/.pivotal/" TEMP_FILE = TEMP_DIR + "temp.yml" CONFIG_FILE = TEMP_DIR + "config.yml" unless File.directory? ...
0
votes
1answer
47 views

Math calculation refactoring in JavaScript

Here's the full source to a plugin I'm developing, the relevant code I want to refactor is: function measure($element, $bubble){ var scrollTop = $window.scrollTop(), viewportHeight = ...
2
votes
5answers
238 views

Do I need to reduce the number of levels in the code?

I have this method that reads a file into a hashmap. I feel like there are too many levels in this code with all these tries, ifs and so on. How do you think this can be improved? public static ...
2
votes
3answers
137 views

Need an advice - refactoring

I'm making a comparing section, which I've just started typing, trying to get something working. It's working now, but as you can see its pretty messy. I feel this could be done in one or two less ...
6
votes
7answers
313 views

How to get rid of semantic duplication

I am breaking my head with how to get rid of semantic duplication(Code that is syntactically the same but does different things). I can't find anywhere a post or something that mentions a bit how to ...
7
votes
0answers
151 views

I've written an aimbot for an open source FPS game. Any suggestions?

The game is Assault Cube. Here is the source code: /* Control + 0 = enable aimbot */ #include "stdafx.h" #include <math.h> const float pi = 3.14159265358979f; /* * I am using int* as ...
3
votes
1answer
72 views

JSON AsyncTask refactoring to improve quality?

I'm new to Android. I was wondering if anyone had any suggestions. It's basically an AsyncTask to get a remote JSON array and put it into a native array. Would be very grateful for suggestions. ...
3
votes
2answers
67 views

How to refactor this Ruby method?

The new_string code in this method does not seem idiomatic. The goal is to not mutate the string passed in, which I believe is a good practice. This method changes all URL's in the string into an ...
12
votes
1answer
474 views

i want to improve my program — what questions could/should i ask myself during the re-write?

tl;dr - i want to adopt good coding habits now. the below code was written under tight constraints. we don't do assignment post mortems in class to discuss "real world" best practices -- we just get ...
4
votes
1answer
91 views

Ruby: refactor simple string method for aligning DSV text

GOAL: Accept DSV strings where the delimiter may consist of more than one character Accept DSV strings where there are no embedded delimiters Output text with no modification to the source string ...
2
votes
1answer
62 views

How do I refactor this ActiveRecord object to lessen dependency on callbacks?

I have an Order object that belongs_to a BillingAddress and a ShippingAddress. I want to present my user with only ShippingAddress fields and a checked checkbox indicating that the billing address ...
2
votes
1answer
67 views

Refactor code for API wrapper

I am looking for ways to improve my API wrapper for Pocket. So far, my code is quite compact and nice (I think), but I feel like there must be a better way to do this. This is the part where I think ...
1
vote
2answers
82 views

how to refactor this java [Android] code

I have this code to generate some tables in my PDF document for my android app. It works fine, I just think I need to refactor it, as basically is the same structure repeated 3 times. //tables! ...
2
votes
1answer
228 views

Improving my floating-point binary/decimal/octal/hex converter

I've finally decided to design a class for this program, but the code still looks messy. I'm also concerned about DRY, which is complicating things for me. Overall, I'm not too satisfied with this ...
2
votes
3answers
57 views

Ruby: check if email address contains one of many domains from a table, ignoring the subdomain

I'm trying to validate email addresses as being from certain universities. I have a table, 'University', which is full of university domains. University email addresses often have different ...
1
vote
0answers
91 views

How can I refactor this method so I don't use it in multiple places?

I have the following method which I use in multiple places, but it only differs by a few different things, so I was wondering how I can refactor it so I can have it in a common class and call it from ...
2
votes
2answers
32 views

Refactoring an interruptable thread

I have a long-running task that processes an input file and then uploads it to a web server. The processing part can be interrupted (with cleanup) but the upload shouldn't be interruptable so that we ...
0
votes
2answers
70 views

Re-factoring amateur ruby code

I am new to ruby and I would be grateful if I need help with re-factoring my code. class Beam def initialize puts "Please specify span of beam" @span = gets.chomp.to_f puts "How many ...
1
vote
1answer
50 views

It there a pattern used to process a same function but assign the result to a different variable regarding to a different condition?

Say I have a code snippet like this if(string.Compare(isStandardFlag,"STANDARD",true)==0) { hearingID = centreSession.standardID; centreSession.standardOutcomeID ...
1
vote
1answer
57 views

Refactoring Java transmitter delegate implementation

I have 3 classes: a transmitter, a view for displaying and a recording view for flushing the screen contents into a file. The view and the recording view classes register themselves from their ...
1
vote
2answers
89 views

CRUD Menu creation - how best to refactor?

I would like to re-write this c# code so it is easier to understand. Should I create a separate function to configure a menu item? Is there is some kind of using statement so I only need to mention ...
0
votes
2answers
42 views

Readability question

Which one of these two would you prefer? The first piece of code is shorter and less noisy (especially when embedded in nested control structures), the second piece seems to me a little more correct ...

1 2 3 4 5 6