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.
5
votes
3answers
143 views
Refactor jQuery multiple click() event handlers
I'm using basic jQuery to render tab data. I was wondering if anybody could comment on how to refactor the click() event handlers, and any general guidance or advice.
Here's the code/output in ...
1
vote
1answer
32 views
Better way of comparing integers
I wrote this class which is comparing some values, how can I improve its performance and maybe make it prettier?
You can see at the bottom what type of data it requires, also the array size can reach ...
2
votes
2answers
36 views
Checking empty object
Is there a better method for covering errors in my case? I am looking for best practice for now and future instances.
Foreseen errors that could arise:
No attributes at all
Some attributes could be ...
1
vote
1answer
34 views
How am I supposed to write a binary tree (S-Expression) pretty printer in C?
OK, I feel like I am doing something really wrong here. I'm just trying to create a binary tree, and a pretty printer for it. My approach is looking so bad I can't even...
...
7
votes
1answer
121 views
Unit conversion activities
Please review these activities which handle converting units in an Android app:
I would appreciate any guidance and advice on code refactoring and different design patterns or strategies that I ...
3
votes
3answers
120 views
6
votes
2answers
66 views
Planning a rather large refactoring of physics code in a good way?
I have a large file that I want to refactor. My idea is to make helper classes with helper methods so that I can modularize methods.
Is that a good idea? For instance before refactoring:
...
2
votes
1answer
35 views
ListView with a search filter
I have this piece of code I've been working on for quite some time. It's a ListView with a search filter. Inside each row, it contains a user Image, a User's name and how many friends they have in ...
5
votes
1answer
236 views
5
votes
2answers
195 views
1
vote
2answers
194 views
Code duplication for just an if condition
I have two methods that are near-perfect duplicates. There is of course a code smell. The only thing that changes is the condition to increment a variable.
Language: Java7
...
3
votes
1answer
35 views
Personal Project for managing my Bookmarks - v2
I had asked earlier for review of parts of my JS file earlier and review of the complete JS file of my project. Now I have made changes as per the suggestions. Here are the files. I would like to get ...
5
votes
1answer
54 views
How can I optimize this SQL ranking generator query?
I have a World Cup fixture app where people can guess the results of the matches. Everything is working great, but each time I update the ranking, it takes 20 minutes for just 3000 users. So there ...
8
votes
4answers
467 views
Is this an efficient use of a boolean method?
This is sort of a follow up to a previous question (Do I have any SQL leaks?).
I have changed some things around and am working on a solution where I use Active Directory to gather information about ...
3
votes
3answers
113 views
1
vote
0answers
27 views
A notification / interception implementation for AngularJS
I was in need of a thing that is able to inform my users about recent activities as well as intercept any action with a modal (e.g for undo purposes)
I decided that I will go for an independent ...
5
votes
1answer
49 views
Avoiding repetitive code for timestamping and updating status
This is some boilerplate I found myself writing on a new abstract class. It seems ripe for refactoring, but I'm not sure the best way to implement it more effectively. Is there a pattern for these ...
-2
votes
1answer
40 views
Optimizimg ugly if else loop in python [closed]
So, I`m getting some values from large nested dictionary.
s_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] and f_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] ...
3
votes
0answers
63 views
Refactoring eBay webform into a more structured pattern
I've been working with this code for quite some time, trying to figure out how I can break it up. It feels very clunky and unorganized. The code takes in a hash that comes from a webform and also ...
4
votes
1answer
71 views
Personal project for managing my bookmarks
I am working on a personal project for managing my bookmarks, which is basically a web page to manage my bookmarks by categories. Managing here means everything - adding, viewing, updating, searching ...
2
votes
1answer
64 views
Adding, deleting elements as per autocomplete results - updated
I am working on a Python/Django project which has turned into a JavaScript/jQuery project due to the amount of asynchronous functionality that I thought to add.
There is a JavaScript file which is ...
4
votes
2answers
59 views
Refactoring switch case statement in different classes
The original code: Refactoring conditional statements among different classes
I am now doing it continually. I fixed a few part as mentioned.
...
-1
votes
1answer
57 views
Refactoring duplicated code
How can I remove duplicated code?
It's hard to me because I use different service class and model each code.
...
5
votes
1answer
71 views
OOP Decision Maker Class - ServerArbiter
I am writing a ServerArbiter, the job of which is to make a decision about which server to "choose" given a set of rules. The aim is to be able to add / remove ...
2
votes
2answers
104 views
Refactoring conditional statements among different classes
I wonder there is any method of refactoring nested condition. It's just the same content with different contents and different classes which looks bad. I really want to reform this code which looks ...
3
votes
0answers
67 views
Ruby on Rails text editor
I'm currently building a text editor using contenteditable and RoR back end. As the editor is WYSIWYG and trying to follow DRY, I used only one file to 3 actions: Show, Edit and New.
Edit and new ...
6
votes
1answer
111 views
Refactoring a LINQ query that (sometimes) returns null
I have the following LINQ query that should return a result for each Request. I'd prefer to have the query translated to ...
4
votes
1answer
95 views
Simplifying if else statements in Python code snippet
How can I simplify and optimize this code?
...
7
votes
2answers
109 views
A Ruby sorting program for multiple criteria
This code review expands on an earlier one that deals with generating a football table from match data. This review deals with ordering said table based on several criteria.
Your ...
1
vote
1answer
23 views
Move update_attributes into class and check for non-nil params to update only
There are a number of things wrong with the code here:
...
4
votes
1answer
61 views
Small football table builder in Ruby
Please review this small program I wrote to create a World Cup Group Table. You feed the program match info, and it builds a table based on that info.
...
3
votes
2answers
108 views
Implementing repository pattern and DAL with stored procedures
Using .net 3.5, implementation of the repository pattern along with enterprise library 5 and stored procedures. Did not use EF, stored procedures already available and VS2008 is limited to EF 3/4.
...
5
votes
2answers
87 views
Domain Name Service Class
I recently wrote a DSN class for use with the Access flavor of VBA. I'm preparing to refactor and would appreciate feedback.
I am aware of two issues.
I added the ...
7
votes
3answers
257 views
Scrubbing user input
I'm taking user input from a file in form (1, 2, 3) to create a color, and I just wanted to know if I was taking most cases into account, and if there is any way I ...
1
vote
1answer
44 views
Robots files generation - simplifying foreach code
I'm trying to figure out if there's a way I can simplify this code which is used to generate a robots.txt file with numerous rules. Different files/folders are separated in separate arrays because ...
3
votes
2answers
195 views
Refactoring a very long method for better maintability
I am currently working on a piece of legacy code that I inherited.
Current java version is 6, but this will change in the next few weeks to java 7. (edit)
I think i might have been working on it for ...
2
votes
1answer
54 views
Ruby on Rails: refactor big search method
I have big search method in my model that corresponds to search a proper Car.
It looks like this:
...
3
votes
4answers
81 views
Helper function to return a string based on passed object and some defined rules
In my application, a notification should be displayed when a chat message arrives. There are some rules which decide what notification message is to be displayed.
I have created a helper method ...
2
votes
0answers
61 views
Web Crawler in Java
I've written a working web crawler in Java that finds the frequencies of words on web pages. I have two issues with it.
The organization of my code in WebCrawler.java is terrible. Is there a way I ...
6
votes
2answers
85 views
Optimize CoffeeScript comparison function
I've wrote this CoffeScript function to compare values in a table, but it turned out to be a HUGE function.
Since the code is really really long, you can find it here as well.
Code explanation:
The ...
3
votes
0answers
34 views
Most intuitive way to register “commands” in an extensible IRC bot in Go
I'm writing an IRC bot as a toy project, and one of the goals is to be easy and straight-forward to implement and register new commands.
As I'm new to Go, I don't know which would be the "Go way" for ...
1
vote
1answer
52 views
How to re-factor dynamic menu code to OOP in a MVC framework?
I have a MVC framework, and I am struggling with the following dynamic menu code.
A menu is pretty much HTML, so technically it should reside in the View, but the dynamic part is driven by PHP and a ...
6
votes
2answers
161 views
Correct use of procs in Ruby
I wrote a Ruby gem to analyse strings for word length, word density, and a few more hand methods...
The Counter class accepts a filter (String). The class will ...
1
vote
0answers
58 views
Speed problems with SetValue, ToType and Reflection
I have a 'speed problem' with a program I'm currently developing. I already have encountered the methods which costs some time.
...
2
votes
0answers
71 views
Speed problems with SetValue, ToType and Reflection
I have a 'speed problem' with a program im currently developing. I already have encountered the methods which costs some time.
...
1
vote
2answers
43 views
Refactoring a function with different signature
I call several WebServices which return each a different exception type:
...
3
votes
2answers
39 views
A more elegant way of changing a single jQuery plugin option on window resize
I'm looking to change a single jQuery plugin option when the window hits certain breakpoints.
The code below works, however I'm conscious of repeating code and feel there is a more elegant way ...
1
vote
1answer
36 views
Script that creates an active CSS on link
I have a script that creates an active CSS on link, but I think there are a lot of if statements. Can someone help me refactor this?
...
4
votes
1answer
33 views
Counting items in categories
I'm an experienced programmer that also has a little experience with functional programming, although mostly theoretical (as in hobby-level reading and very minor projects).
I recently decided to ...
5
votes
2answers
164 views
Shortening / refactoring code for checking for a win in TicTacToe
It looks like it should but I can't see how.
I have my methods <= 5 lines but that's as far as I got:
...