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)

5
votes
1answer
71 views

Refactoring chart generator in Linq

I'm kinda curious how I'd refactor this in the best way. I've only used Linq for simple queries. What it does: Depending on the type that is submitted, we're grouping events or payments by ...
4
votes
3answers
68 views

Extracting pattern and simplifying testing

I observe the same pattern in a number of my classes but can't extract/abstract it due the tight coupling inside each particular implementation. Having the class accepting an optional number of ...
3
votes
2answers
60 views

Hangman game code refactoring

I would like some help refactoring this code. This is to improve some of the nonfunctional attributes of the software to improve code readability reduce complexity to improve the maintainability of ...
7
votes
5answers
186 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 ...
4
votes
2answers
90 views

Are redundancy and reflection my only options here?

I have a function - TriggerNotifications - that accepts a NotificationType. The Type determines which settings I should pull from the User. The code looks like this: public void ...
1
vote
2answers
27 views

Trouble searching database, filtering results, adding longs (ugly code)

My needs outpace my abilities, this code (mostly) works, but it is really ugly, doesn't always add correctly, and is in desperate need of some help refactoring. I can't wrap my head around what needs ...
7
votes
1answer
95 views

Moving method from derived class to base

I've some classes (Derived1, Derived2, etc.) derived from class Base. All of derived classes have a following methods (reduced sample): void Derived1::handleTimer(const StatusType &st) { if ...
3
votes
1answer
89 views

Need advice on file/directory enumeration code

In various projects I need to enumerate all files and folders from a specific root folder, either on a local drive or across a network. I've broken the task down into two IEnumerable implementations ...
0
votes
2answers
93 views

Trivia game refactoring

I am trying to re-factor (improve design of existing working code) with the following principals: Switch statements removal. Encapsulate Field Extract Class Extract Interface Extract Method Extract ...
0
votes
1answer
61 views

Extract code that makes class shared_ptr construct-able only

I've tried using CRTP, but the forces the class to befriend CRTP Base. template <typename T> class SharedConstructable : public std::enable_shared_from_this<T> { typedef ...
7
votes
1answer
129 views

Poker Hand Evaluator, take 2

This is following up on my previous attempt, which was admittedly done fast and not-so-well. This code attempts to allow comparing two poker hands to determine a winner, not only evaluating a given ...
2
votes
1answer
37 views

Refactoring Google Maps geocoder

I have a Google Maps Geocoder and I am looking to refactor it. The user enters address details into a form where at the bottom there is the option to show on map. First the map is hidden The user ...
4
votes
2answers
127 views

Generic DAO written in Java

I initially thought that this was just an architecture issue so I placed it on programmers as Thoughts on refactoring a generic DAO. Then I asked on codereview meta here and decided to put up the code ...
2
votes
3answers
71 views

Refactor if statement with object-oriented style

I've this block of code: Edit: more accurate code: public void Execute() { ... var memo = BL.GetMemo(); ... if (memo.testCond1()) //like memo.isLongText() doSomething(); ...
2
votes
1answer
84 views

Searching over more models rails

I'm trying to implement search over two models. In this example Book and Article. Here are the attributes from both of these : Article(id: integer, magazine: string, title: string, body: text, ...
0
votes
0answers
36 views

Symfony2: Refactor messy Controller action

I have a fairly ugly controller method I would like to refactor / extract. I can only test this in a integration type test which kind of signals a code smell. The method processes the form and needs ...
2
votes
2answers
45 views

Beautify / Refactor some Python / Django Code

So, in the following code, I am getting the best available set of rates. It gets the job done, but I think it's too long for what it does. How could I shorten this code and still get the same thing ...
3
votes
3answers
65 views

A way to make input text sizing function more elegant?

So I have this jQuery function I wrote up to set the size of an input based off of its data. In this case I have already figured out the widths for each character based off of a 12px font size for ...
3
votes
4answers
158 views

Refactor code to find four co-linear points

I am relatively new to Java, but have been reading up on how to improve the quality of my code. I am writing a system where I take in a series of points from a file with x and y co-ordinates and by ...
1
vote
0answers
35 views

Symfony2: Extract method from controller, form events, remove conditional

I have a fairly ugly controller method I would like to refactor / extract. I can only test this in a integration type test which kind of signals a code smell. The method processes the form and needs ...
0
votes
1answer
30 views

Daemon code for updating blog

I have a bit of code that I use to update my blog. Basically, I send an email to a particular address, and every x minutes the daemon fetches the emails, creates the files, executes middleman and then ...
0
votes
1answer
46 views

Reading and writing an unknown character into an appropriately named file

I would like to refactor this code a bit further and make it better and more generic. As of right now, it is doing what I want it to do (reading a list of URL's, splitting the query and the ampersand ...
3
votes
1answer
23 views

Using a .csv file to insert data into the Django model

I have a script that uses a .csv file into insert data to the Django model. Now, I wonder if there's a better way of doing this. with open('some/path/to/file.csv') as f: reader = csv.reader(f, ...
0
votes
2answers
73 views

C code displaying random datasets

I have much more experience with PAWN scripting language, but I'm digging into K&R book (I think it is it), and trying some stuff on my own. #include <stdio.h> #include <stdlib.h> ...
1
vote
1answer
124 views

Python API client design and best practices

I'm creating a Python API client, after thinking and checking some open source Python clients I created this class, and I'm looking for any feedback (design, best practices...), this is an example URL ...
4
votes
3answers
97 views

Refactoring a function to return all scores above a certain threshold

I am currently learning JavaScript and wanted to fellow coders to review a function that I had written. I am looking for feedback particularly on: Whether I have followed best practice and ...
1
vote
2answers
110 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
193 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
47 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 ...
2
votes
1answer
109 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
2answers
429 views

iOS: Code review of MasterViewController

I plan on including this work in a portfolio. Question: Will this code get me hired or laughed at? More Specifically: How would you rate the general complexity of the code? How bad does the code ...
1
vote
1answer
70 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
79 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
140 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 ...
1
vote
1answer
124 views

iOS App ViewController Refactoring Guidance

My question is: How can I most effectively refactor the code in these 2 ViewControllers. I'm familiar with subclassing in objective-c and have used it extensively else where with NSObjects and ...
3
votes
1answer
76 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
201 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
518 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
97 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
70 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 == ...
3
votes
2answers
119 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
81 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
234 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
47 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
62 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 ...
2
votes
1answer
128 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
1answer
85 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
83 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
50 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
97 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 ...