A `code smell` is something which is a sign of a possible problem in a program.
6
votes
2answers
863 views
Bad practice to have try / catch in constructor?
I have a constructor which sets a member variable. The setting of this variable throws an exception. Should I be throwing the exception in the contructor or enclosing the try/catch like below. Is ...
6
votes
2answers
125 views
Left hand search in string
the requirement for our search query is to look for all search words in the beginning of vehicle manufacturer, model and variant name. Case insensitive. The word being a string of characters separated ...
5
votes
1answer
2k views
Polling loop - Always a bad decision?
I had a need to isolate some long-running blocking calls in a background thread of my app. I also needed to keep this thread running indefinitely, because COM would complain if some object I created ...
4
votes
3answers
283 views
Is this interface too “god-like?”
I have an MVC framework I've written. I'm trying to abstract out ASP.Net specific bits as well as make it more testable. Previously, I relied on HttpContext.Current in many places, which proves to be ...
3
votes
3answers
218 views
Write it better/neat/fast (if condition)
How to write following if condition clean/fast/readable.
Any one of the fields 'address', 'city', 'district', 'province' can be null. I want to make full address by concat all these fields. Like
...
3
votes
5answers
302 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 ...
3
votes
1answer
65 views
Better Javascript to find unique values in an array
My objective is to make an array of unique keys from a list of objects. Example:
Input:
var input = [{"a":1, "b":2}, {"a":3, "c":4}, {"a":5}]
Output:
[ "a", "b", "c" ]
Current approach:
var ...
3
votes
2answers
118 views
Improving Python script to drop HTML part of multipart/mixed e-mails
I have a working script that I wrote in Python which for e-mail messages that consist only of a plain text part + an HTML part, discards the HTML and keeps only the plain text part.
The script is not ...
3
votes
4answers
150 views
Is static method calls to a server a Java bad code smell?
I'm developing an Android app that performs several requests to a server using the AndroidAsynchronousHttpClient. One of these requests (as an example) is responsible to send the username and ...
3
votes
1answer
298 views
Using switch to avoid duplicate code. Is there a better way?
I recently changed one of my methods and used this pattern (names are changed, a dose of humor applied for the exception):
switch (myEnum) {
case e1:
// do stuff
if (!alsoApplyCodeForE2) {
...
3
votes
0answers
70 views
Scala Play Controller - Refactoring out Duplication for Restful Web Services
I'm new to scala and I'm noticing I have some repeating code in my controllers.
I'm wondering if anyone can give some hints for traits and parameterization for eliminating duplicate code for basic ...
2
votes
3answers
124 views
How to re-factor a common String comparison
Code below is scattered all over the code base :
if (StringUtils.contains(manager.getName, "custom")){
}
It just checks if an object attribute contains a predefined String and if it does, enter ...
2
votes
1answer
193 views
my constructor is doing work. Is this a code smell in this example?
I have created a queue in javascript. This queue also has blocking take(). As you all probably know this is not really true, because javascript does not have threads. It just wait until element has ...
1
vote
1answer
102 views
Help me simplify this gigantic class
I'm trying to think of ways to separate things out. I'm open to ideas, or if you see anything blatantly wrong, I'd like to know that too.
Generally, I'm happy with this, but the sheer size of the ...
1
vote
1answer
62 views
How to improve readability of a big lisp function
My main method (remove-random-edge) looks quite difficult to read. I'm new to list, so would appreciate any advice on how to improve the code.
(defun find-node (node graph)
(find-if #'(lambda (i) ...