Questions tagged [code-smell]

Determining what is and is not a "code smell" is subjective, and varies by language, developer and development methodology. Before you ask if some technique is a "code smell," ask yourself what the consequences to your specific project would be, if you used the technique. Simply asking whether something is a "code smell" or not is too subjective.

Determining what is and is not a code smell is subjective, and varies by language, developer and development methodology.

Before you ask if some technique is a "code smell," ask yourself what the consequences to your specific project would be, if you used the technique. Then, ask about those specifics. Simply asking whether something is a "code smell" or not is subjective, and increases the likelihood that your question will be closed.

167 questions
305
votes
19 answers

Are #regions an antipattern or code smell?

C# allows the use of #region/#endregion keywords to make areas of code collapsible in the editor. Whenever I do this though I do it to hide large chunks of code that could probably be refactored into other classes or methods. For example I have seen…
Craig
  • 4,302
  • 3
  • 21
  • 21
101
votes
9 answers

Is putting general-use functions in a "helpers" file an anti-pattern or code smell?

Is it an anti-pattern or code smell to put "general use" functions (examples below) into a catch-all file named "helpers" or "utils"? It's a pattern I've seen quite a lot in the JavaScript world, which I've also seen with other languages. By…
old greg
  • 909
  • 2
  • 4
  • 6
92
votes
7 answers

Short circuit evaluation, is it bad practice?

Something that I've known for a while but never considered is that in most languages it is possible to give priority to operators in an if statement based on their order. I often use this as a way to prevent null reference exceptions, e.g.: if…
innova
  • 1,031
  • 1
  • 8
  • 11
80
votes
6 answers

At what point/range is a code file too big?

I'm finding lots of 2-3k line files, and it doesn't really feel like they should be that big. What is a good criteria to objectively call a source code file "too big"?, is there such thing as a maximum amount of lines a source code file should…
dukeofgaming
  • 13,943
  • 6
  • 50
  • 77
78
votes
17 answers

How to train yourself to avoid writing “clever” code?

Do you know that feeling when you just need to show off that new trick with Expressions or generalize three different procedures? This does not have to be on Architecture Astronaut scale and in fact may be helpful but I can't help but notice someone…
Dan
  • 2,902
  • 1
  • 25
  • 30
69
votes
2 answers

What is a" feature envy" code and why is it considered a code smell?

This question on SO talks about correcting what the OP thought is feature envy code. Another example where I saw this nifty phrase being quoted is in a recently given answer here in programmers.SE. Although I did drop in a comment to that answer…
Geek
  • 5,107
  • 8
  • 40
  • 58
54
votes
10 answers

Are flag variables an absolute evil?

Are flag variables evil? Are the following kind of variables profoundly immoral and is it wicked to use them? "boolean or integer variables that you assign a value in certain places then down below you check then in orther to do something or not,…
dukeofgaming
  • 13,943
  • 6
  • 50
  • 77
52
votes
12 answers

If your unit test code "smells" does it really matter?

Usually I just throw my unit tests together using copy and paste and all kind of other bad practices. The unit tests usually end up looking quite ugly, they're full of "code smell," but does this really matter? I always tell myself as long as the…
Buttons840
  • 1,856
  • 1
  • 18
  • 28
51
votes
5 answers

Is it considered Pythonic to have multiple classes defined in the same file?

In working with python for the first time, I've found that I end up writing multiple classes in the same file, which is opposed to other languages like Java, which uses one file per class. Usually, these classes are made up of 1 abstract base class,…
Ampt
  • 4,605
  • 2
  • 23
  • 45
47
votes
10 answers

Is there any reason to use "plain old data" classes?

In legacy code I occasionally see classes that are nothing but wrappers for data. something like: class Bottle { int height; int diameter; Cap capType; getters/setters, maybe a constructor } My understanding of OO is that classes are…
Michael K
  • 15,539
  • 9
  • 61
  • 93
39
votes
8 answers

Are there architecture smells?

There are tons of resources on the web referring to and listing code smells. However, I've never seen information on architectural smells. Is this defined somewhere, and is there a list available? Has any formal research been done into…
C. Ross
  • 2,926
  • 2
  • 26
  • 42
33
votes
3 answers

How to tackle a 'branched' arrow head anti-pattern?

I recently read this question that features, the arrow anti-pattern. I have something similar in code I'm trying to refactor except that it branches. It looks a little something like this: if(fooSuccess==true&&barSuccess!=true){ …
AncientSwordRage
  • 1,033
  • 1
  • 11
  • 24
32
votes
6 answers

Multiple classes in a single .cs file - good or bad?

Is it advisable to create multiple classes within a .cs file or should each .cs file have an individual class? For example: public class Items { public class Animal { } public class Person { } public class Object { …
Sergio
32
votes
9 answers

Is there a better way to use C# dictionaries than TryGetValue?

I find myself often looking up questions online, and many solutions include dictionaries. However, whenever I try to implement them, I get this horrible reek in my code. For example every time I want to use a value: int x; if…
Adam B
  • 1,506
  • 2
  • 12
  • 20
31
votes
9 answers

Are init() methods a code smell?

Is there any purpose for declaring an init() method for a type? I'm not asking whether we should prefer init() over a constructor or how to avoid declaring init(). I'm asking if there is any rationale behind declaring an init() method (seeing how…
1
2 3
11 12