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)

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 ...
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. ...
3
votes
3answers
254 views

Client trip type contracts

I want to make this code generic, so that I could remove if/else and recursive for loops. ...
1
vote
0answers
15 views

ForceNumeric plugin [on hold]

I found this plugin on net, and I customized it for maxIntegerPlaces and AllowDecimal (to allow only single ...
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 ...
3
votes
2answers
347 views

Password checker containing many conditional statements

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, ...
7
votes
3answers
152 views
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 ...
1
vote
2answers
83 views

Trying to use “this” to refer to a class's instance variable inside a function within the class's method in JavaScript

Hope that title makes sense. This is part of an object I have: The event listener attaches to the correct marker passed in the parameter but inside the function, ...
5
votes
1answer
55 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 ...
8
votes
5answers
333 views

Abstract Pet class

As a student of C# right now, I am trying my best to get a grasp on many of the systems being taught. I just completed Week 1 of a C# 102 class and the class was assigned a bit of homework. I am ...
2
votes
1answer
224 views

Parse in currency rates of major cities

Background: I'm creating a website that parses in currency rates of the three major cities listed below in the $cities array. I'll explain my code as I go along. ...
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 ...
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 ...
4
votes
2answers
410 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 ...
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: ...
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: ...
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
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 ...
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
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 ...
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 ...
7
votes
2answers
269 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
770 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
89 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. ...
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 ...
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 ...
10
votes
1answer
142 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. ...
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 ...
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 ...
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? ...
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. ...
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 ...
0
votes
0answers
40 views

Implementing a login client

I have a lot of functions in this class to implement a login client. How do I modularize it ? ...
4
votes
2answers
113 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. ...
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 ...
7
votes
4answers
474 views

Getting list items

Is there any possibility of refactoring this code? In class A: ...