Tagged Questions

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.

learn more… | top users | synonyms (1)

3
votes
2answers
48 views

Can this class be improved?

I have this class whose code I pasted in full. The CredentialsManager class is not shown here as all it does is return the DB connection variables. My question is if this class can be improved or if ...
3
votes
4answers
93 views

Refactoring a class hierarchy to remove subclasses

I have the following class inheritances hierarchy: First the abstract parent class: <?php abstract class SegmentParserAbstract{ /** @var ParserResult */ protected $_result; protected ...
2
votes
1answer
55 views

Can someone more experienced with MVC routers, review my RequestRouter::dispatch() and Request::parseURI() methods?

I'm hoping that the more experienced devs here can help me improve these methods. I'm building a basic MVC framework for myself (as a learning project,) and I'd really appreciate your insights. Things ...
0
votes
1answer
22 views

Is it possible to write this staging/release nginx config in a cleaner way?

I don't like how this config has so much duplication. Any suggestions on how to at least shorten it somewhat? Normally we only have one server block as the staging server is separate from production, ...
5
votes
3answers
75 views

Refactoring jquery same code but different selector

How to refactore this $("#txtShippingAddressFullName").change(function () { $("#txtBillingAddressFullName").val($(this).val()); }) $("#txtShippingAddress").change(function () { ...
2
votes
2answers
112 views

Cleaner Code for custom query

Is there a cleaner way to do the following? friend_ids = [1,2,3,4,5] friendIDsQuery = "" friend_ids.each_with_index do |friend_id, index| friendIDsQuery += "SELECT id FROM test WHERE user_id = ...
2
votes
2answers
75 views

Refactor jquery (coffescript) code with checkboxes

I have two different set of checkboxes. With the coffescript code below I set the maximum amount of checkable items at 3. I would like to refactor this code, to be cleaner and compact, but I can't get ...
3
votes
5answers
261 views

How to avoid passing variable to a method again and again

Following is a chunk of code from my class which generate PDF document. I am refactoring my code and in the process I have created short methods. But I have to pass 'table i.e PdfPTable' to my methods ...
0
votes
2answers
73 views

Refactoring functions that generate string with random letters, numbers or mixed chars?

The bellow functions are used to generate a string with random characters, and they have a parameter to specify the string length. The string can be composed of letters, numbers or a conjunction of ...
0
votes
2answers
27 views

JQuery html() .replaceWith() need assistance with refactoring

I am very new to JQuery and am not familiar with all its methods. How would you refactor showNextTip() method (it looks very ugly to me) <div id="dialog-tip" title="Did You Know?"> ...
1
vote
0answers
26 views

How to deal with almost the same enums? [migrated]

I need to define enums in several classes. The majority of fields are the same in all of the enums. But one has one or two more fields, another has fewer fields. Now I wonder what is the best way to ...
4
votes
1answer
153 views

Comparing multiple fields from two tables, looking for matches, updating 2nd table

In my never ending quest to improve my coding skills I am requesting peer input on the following code logic. I am asking because I'm -NOT- an expert, but would like to be one day. Source material and ...
3
votes
1answer
49 views

How to refactor common methods that depend on local variables into a base class

I'm using Node.js and am creating some models for my different objects. This is a simplified version of what they look like at the moment. var Foo = module.exports = function () { var values = ...
4
votes
2answers
106 views

Would be possible to refactor this PHP code more?

I really don't like the so many return statements. Anyone think that this could be refactored more? public function validate($value, Constraint $constraint) { if('' === $value || null === $value) ...
4
votes
1answer
54 views

Refactoring code finding if Binary Tree is BST

I have written an code to find if a given tree is a BST. Need help in refactoring it. Some of the things I am looking are. Getting Rid of temp variables (As suggested by Martin Fowler) Combining ...

1 2 3 4 5 11
15 30 50 per page