Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.
0
votes
2answers
32 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
37 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
45 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 ...
2
votes
1answer
165 views
Is this spaghetti javascript code? How can it be refactored with a javascript library or framework?
The code allows you to select an area from the left column and another area from the right column followed by clicking on the Choose button which sends the chosen areas to the server:
<html>
...
1
vote
2answers
81 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 ...
1
vote
2answers
96 views
Code review and refactoring this Python program
Here's a simple Python Flask app. It uses the wikidot API to transfer pages between two wikis. I'd like to hear your input on the best way to refactor this code. Here are a couple of questions I ...
4
votes
1answer
53 views
Is aliasing repeated code as internal lambdas a good coding practice?
When writing code that contains repeated blocks, it is good practice to extract it in an outside function.
C++11 also allows me to extract the code into a lambda, within the function body. Are there ...
3
votes
1answer
230 views
Refactoring a Telnet parser
I'm writing a Telnet parser in Haskell that can run within any monad that implements some event-handling functions. When it finishes processing a block of input - whether because it read it all or ...
4
votes
1answer
47 views
My VBS Word macro is really slow, looking for advice!
So, I have a 100page long docx format document. I'm using a macro written in VBS to extract some information and then just generate a table from them.
I iterate through the paragraphs and store the ...
0
votes
2answers
39 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
votes
1answer
70 views
How to create 3 objects using one form only if each one is valid? [closed]
I want to create Job, Employer and Company using one form.
Model
class Job < ActiveRecord::Base
accepts_nested_attributes_for :company, :employer
belongs_to :company
belongs_to :employer
...
1
vote
1answer
175 views
Trying to refactor method to remove argument added to URL
Background:
I'm creating a website that parses in currencies rates the three major cities listed below in the $cities array.
I'll explain my code as I go along.
<?php
// Feed URL's //
...
-1
votes
1answer
112 views
please review my switch case code
Now I hava a enum param and wants to do something which is acording to the enum param value.
While the enum param is too much and my method will become too long.How can I refactor my code?
I know ...
7
votes
6answers
549 views
Complex if else
How would you write this?
string halfADayOff = "Half a day off";
string oneDayOff = "One day off";
string days = "NoDaysOff";
if (typeOfDelegation)
{
if ((differenceInDays == 0) ...
1
vote
0answers
25 views
Converting data in a Rails Migration using the model
Lets imagine we have an Article entity, with data imported from a legacy database. It contains an appendix column with type integer. This column is always filled with values 0, 1 or nil, so we decide ...