Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Use this tag only when you're looking for constructive feedback for rewriting parts of your existing code into better, cleaner code.

learn more… | top users | synonyms (1)

3
votes
3answers
40 views

Math Equation Solver

I made this math script, where you enter an equation and it solves it for you. I was wondering what you thought of the code, and what I could have done better or what doesn't follow Ruby best ...
3
votes
1answer
62 views

Possible to shorten my code of error displaying (if-statements)

Is it possible to shorten this piece of PHP code? Honestly, I think it does not look clean but like a mess. ...
1
vote
0answers
15 views

ForceNumeric plugin [closed]

I found this plugin on net, and I customized it for maxIntegerPlaces and AllowDecimal (to allow only single ...
6
votes
2answers
73 views

A source Code Counter

This is from my project codecount I use personally that is very similar to cloc.exe or SLOCCount. The part that I am questioning is where I am calculating when I am in a comment block and have deep ...
7
votes
3answers
152 views

Checking to see whether a document can be deleted

My code looks like this: ...
5
votes
1answer
57 views

Responsive jQuery restaurant menu system

I have a working restaurant menu system - as the user selects a menu it slides into view. The build is responsive, I've used the 'Debounced Resize() jQuery Plugin', however in implementing the ...
5
votes
1answer
56 views

Zombie Smack Down game

So about a year and a half ago, me and my friend started on a game called Zombie Smack Down. It's a text based game written in Ruby. But we were both really new to Ruby when most of it was written. I ...
7
votes
4answers
405 views

E-Commerce 'sale price' calculator

I have code which I need to refactor in order to use in many places. So I tried some solutions but always ending with repeated and messy code. So, I decided to ask what possible best solutions are. ...
4
votes
1answer
59 views

Reducing code duplication in a geometric function

Given a large bounding rectangle ("envelope"), a list of points, and a maximal aspect ratio, the goal is to find a rectangle within the envelope, whose aspect ratio is bounded within the given aspect ...
4
votes
2answers
411 views

How do I avoid duplicated code in these overloaded functions?

I have the following overloaded functions. All the code is the same as except for their format (%s v.s %lu), so I couldn't use ...
7
votes
3answers
135 views

Refactoring method to make it unit testing friendly

I have a completed application which I'm trying to write unit tests for (Yeah I know, talk about bad practices) I have the following class here ...
1
vote
1answer
31 views

Auto-Format GPA while typing : REVISED

I need to further simplify this solution to auto-format a text-box field intended only for the user to enter their college Grade Point Average (GPA). Here is my code: ...
4
votes
1answer
105 views

Am I over-engineering?

So I just jumped to a new project, which uses activerecord pattern. It's a subscription service website. I have the following User object that extends a framework specific ORM object. ...
1
vote
1answer
56 views

A Ruby string analyser

I wrote this script for a code challenge on TreeHouse. I already submitted my code, but I am looking for an after the fact feedback. The challenge was to open a file of text, remove specific words ...
1
vote
1answer
26 views

Object Oriented Modular Closure

The following is some code I just wrote. I keep wondering as always what I can do to make this more efficient. Please help me make this code object oriented and if anyone could help me write ...
5
votes
1answer
66 views

Auto-Format GPA while typing

I'm looking for a more cleaner and simpler solution to auto-format a text-box field intended only for the user to enter their college Grade Point Average (GPA). Here is my code: ...
7
votes
2answers
238 views

Wrapping my head around generators

I am going on with refactoring my code base while migrating from Python 2 to Python 3. I am using generators to make reusable components this time as I am more comfortable with them this time then ...
4
votes
2answers
98 views

How many squares can you see?

With a positive outlook, I posted this challenge at Programming Puzzles & Code Golf. I tried to come up with my own solution to the challenge which is as follows: The output is displayed (not ...
7
votes
2answers
273 views

Repetitive For Loops in 2048 Game

I have the following function defined in a program that implements the 2048 game. I tried condensing the repeating part of the code into one loop containing +1 offset variables for the indices, which ...
13
votes
5answers
771 views

Looking for a cleaner way to write a jQuery function

I've got a piece of code that takes an element, checks where it is, and if it's beyond a set place in the viewport, make the opacity increase to 1. I've made the code so that it only runs the checks ...
4
votes
2answers
82 views

Wait until all files are loaded asynchronously, then run code

I'm an experienced programmer but not too great at JavaScript so I'm looking to see if I'm doing this 'right'. I want to have several files loaded in (Ajax or really AJAJ) and, once loaded, run some ...
6
votes
2answers
262 views

Refactoring Methods With Conditionals

I have always suffered with too many conditionals in some of my methods. The following is a pseudocode/skeleton of one of my method like that: ...
1
vote
1answer
23 views

Remove nodejs/browser specific code in library

I'm the maintainer of the following library on github: https://github.com/edi9999/docxtemplater/blob/master/coffee/docxgen.coffee I want to maintain a library that works on node and in the browser, ...
2
votes
1answer
90 views

Best way to refactor this loop of animations with delay?

I have some animations happening after some delay calls the code to animate. It works fine, but the code to call the functions is not nice. ...
10
votes
5answers
398 views

Refactoring my problem-solution to reduce complexity

I need some help refactoring my solution to the problem below: Problem Statement An Association of Computer Scientists meets on a weekly basis. There is a certain number of seats in the meeting ...
10
votes
1answer
143 views

Probably unneeded returns

This is my first "useful" Haskell program. It's invoked with filenames as arguments where the last filename is the destination to which the content of all other files will be concatenated. As far as I ...
10
votes
1answer
138 views

Refractoring OOP vs. Functional Programming Approach

I am writing a python script that will call mandrills export activity api for every blog on a worpress mu install except for the main site. The script is designed to be called from a cron job on a ...
8
votes
1answer
70 views

Switch-case Monstrosity for CPU Emulator

I am still working on A Z80 CPU emulator and I have decided to prototype it in javascript and then translate it into a faster language, It might be ported to C but more likely is Java - this means I ...
3
votes
2answers
69 views

Readability and cyclomatic complexity of this Ruby code

I consider this two options exactly the same. I prefer the first one but I'm not sure if it's better the second option in terms of cyclomatic complexity or readability. Assuming that this is not pure ...
0
votes
2answers
40 views

Avoiding code duplication in mapping layer between dataRecord and

The following code is for mapping a dataRecord to a class. I don't like this solution since it requires to duplicate the logic of mapping for each field in every method which access to the same table. ...
4
votes
5answers
464 views

How to shorten this code or make it more efficient?

How to shorten up this code? I know there's a way that this kind of code could be shortened, but I don't know how by myself yet. Who can help me? ...
3
votes
1answer
90 views

Genericizing PropertyValues

This should be the last iteration for this code. Question 1 Does this approach make sense or am I heading down the wrong path? Question 2 The only thing I can see to make this better is to ...
7
votes
4answers
198 views

User search implementation

In my Java code I have these three classes. Basically I have a User class, and also a GUI class that holds TextViews and other things (GUI related) for the ...
6
votes
1answer
114 views

How can this python quadtree be improved?

Here's an attempt I've made of implementing the Barnes-Hut nbody algorithm, or its initial stage - The quadtree. That there're lots of lengthy doc strings might excuse the lack of detailed explanation ...
6
votes
3answers
249 views

Next Instance of DRY Refactoring

I'd like some additional assistance on refactoring. This is my latest update for this iteration. ...
0
votes
0answers
41 views

Implementing a login client

I have a lot of functions in this class to implement a login client. How do I modularize it ? ...
2
votes
1answer
76 views

How does this refactored code make my code better? [closed]

According to my lecture notes, there are benefits to refactoring the code from original code to refactor code. Reasons for refactoring: Replace Temp with Query You are using many ...
1
vote
1answer
104 views

Update user's last login date

This function updates the user last login date on the user collection. I guess there are too many brackets and much spaghetti. How can I shorten this code? ...
2
votes
1answer
46 views

Refactoring a String Calculator

I've refactored the string calculator kata as much as I could and tried to maintain single responsibility. Is there anything I could factor differently? The specs can be reviewed here. ...
6
votes
3answers
478 views

Lots of repeating code, trouble refactoring

I'm looking for a design pattern or suggestions that can help refactor my code into something a bit less repetitive. I have a method that has several sequential steps (10-15) that if any of them fail ...
3
votes
2answers
40 views

Elegant way of making a List of an attribute from a list of objects containing that attribute

If this is my class: class Something { UUID id; // Other members } Given a List<Something> things and I want to ...
2
votes
1answer
99 views

Refactoring a Delimiter

Is there a more cleaner approach to this? I'm doing the String calculator Kata posted by Roy Osherove. I realized that my calculator has no way of clearing out a previous expression after calling add. ...
4
votes
1answer
71 views

Improving XNA's default project template

I hope this isn't getting annoying, but I've asked a lot of questions about improving my game lately: How can I improve my game project design? Using the observer pattern with collision detection Is ...
6
votes
2answers
95 views

Read CSV, compute some stuff and prepare data to be sent to GNUPlot

I would really appreciate some good advice on how to refactor a small app: It basically reads a CSV (energy/heat values?), computes some stuff, and then prepares some data which should later be sent ...
10
votes
2answers
157 views

Setting up keyboard bindings using JSON (no reflection!)

I got a lot of good feedback on my other question. So I will take another swing at it, post my revisions, and hopefully get some more. First, the configuration hasn't changed. Here's the JSON file: ...
3
votes
1answer
39 views

Refactor C# OR statement using Linq

How can I write this OR statement better, allowing for growth in number of values? var isNewFile = (progressID == 10 || progressID == 20 || progressID == 21); I ...
20
votes
6answers
3k views

Refactoring large switch statement

Lately I have been trying to extract till I drop. Well not necessarily till I drop, but I've been trying to be more strict and look at some metrics of my code. I have now come along an old class of ...
0
votes
1answer
30 views

Is it reasonable to have separate controller actions for different user registration paths? Or should I refactor into a fewer number of actions?

I have two registration paths in my app. They are very similar and I am curious if I should simplify 4 associated actions down into two actions that handle the same amount of work. Here are my ...
7
votes
4answers
57 views

What is the best way to refactor out “temporal dependence” of instance methods?

For example, suppose in a view class we need to instantiate some UI components and then populate the fields. Something like: ...