Skip to main content

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.

Filter by
Sorted by
Tagged with
8 votes
5 answers
4k views

According to Instanceof code smell, I know using "instanceof" is a code smell, so suppose there is a game with some Tools: Tool.java: public interface Tool{ public void printInfo(); } ...
wcminipgasker2023's user avatar
3 votes
5 answers
812 views

According to Why should I use dependency injection?, "dependency injection" has some advantages, for example: "Non dependency injection" version: public class Client{ private ...
wcminipgasker2023's user avatar
0 votes
0 answers
221 views

For example, suppose I have a mobile app that uses some user data, the DTO: class UserData{ public: Address address; bool isVerified=false; }; class Address{ }; The UserData may be loaded from ...
wcminipgasker2023's user avatar
2 votes
3 answers
242 views

According to https://softwareengineering.stackexchange.com/a/212130/432039, if a class asks another class for the state, and then call methods of that class, it is called "feature envy", eg: ...
wcminipgasker2023's user avatar
6 votes
4 answers
1k views

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know init is a code smell and should be avoided, and one of the solutions is to use a builder to hold the state first ...
wcminipgasker2023's user avatar
-1 votes
4 answers
391 views

I have a loop that I am testing a condition in but if the condition is not met then after the loop is complete, I want to execute another code block: Boolean loopConditionNotMetFlag = true; for (List&...
Devlinite's user avatar
0 votes
3 answers
389 views

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know "init()" method is a code smell, and "physically make them two separate classes" is a way to ...
wcminipgasker2023's user avatar
0 votes
2 answers
823 views

I have a singleton that needs to be initialized at the start of the program and it will live on until the end of the program. As is usual in this pattern, a function initializing the singleton creates ...
Reverent Lapwing's user avatar
2 votes
3 answers
293 views

In legacy code bases, some APIs might be encapsulated by different developers with separate classes many times. Example: public void calculate(int baseIncome) { revenueCalculator.calculate(...
Rui's user avatar
  • 1,935
0 votes
6 answers
1k views

I have to create custom buttons but in order to encapsulate the logic of button creation I've this class (VB.net): Public Class ButtonCreator Public Shared Function CreateBaseButton(Optional ...
Mateo Ezequiel Bertogliati's user avatar
1 vote
3 answers
2k views

I have recently read about the so-called "distributed enum anti-pattern." In particular, as it relates to using enums in conditional statements. (The idea is apparently that if you were to ...
user1713450's user avatar
2 votes
2 answers
229 views

Suppose I have a member function void A::foo(B const &b) where a class B instance is just a bunch of data. Would it not be better to remove the dependency between class A and class B by rewriting ...
maksim_volodin's user avatar
0 votes
2 answers
246 views

Right now, I have this enum, called MemberCategory, defined to be: public enum MemberCategory { MEMBERSHIP("Membership"), GOLD_MEMBERSHIP("Gold"), SILVER_MEMBERSHIP(&...
Mike Warren's user avatar
0 votes
1 answer
98 views

I have an import that needs to grab data from a REST service and import into an web store. It's basically an ETL type of service, but because the REST service can be slow and I don't want to call it ...
user204588's user avatar
4 votes
4 answers
2k views

Say I use GUIDs as keys. Considering the chance of a duplicate GUID being generated being what they are, is code like this considered a code smell? Guid newID = GenerateGuid(); while (dictionary....
Cole Tobin's user avatar
  • 1,533
0 votes
2 answers
2k views

I have an eternal discussion in my work about why "error first" is "worng". In order to ensure what I try to tell with error first is the following code pattern: if condition: ...
Tlaloc-ES's user avatar
  • 387
0 votes
1 answer
88 views

I am writing a control app for a 6-DOF robot. This app can send scripts to the robot, which in turn executes these and thus moves around. In the app a robotprogram can be created by adding 3D ...
Gertjan Brouwer's user avatar
106 votes
11 answers
27k views

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 ...
old greg's user avatar
  • 959
0 votes
4 answers
1k views

Please help me with the following code refactoring, I spent so much time researching it and there's still no clear answer on how to approach it. Any help is greatly appreciated! So, given 2 methods (C#...
Codify's user avatar
  • 11
29 votes
4 answers
4k views

The Law of Demeter makes sense in some obvious cases. # better dog.walk() # worse dog.legs().front().left().move() dog.legs().back().right().move() # etc. But in other cases it seems to lead to an ...
samfrances's user avatar
  • 1,095
1 vote
2 answers
847 views

In Martin Fowler's refactoring book, there is a code smell named "Insider Trading" which I don't understand: Software people like strong walls between their modules and complain bitterly ...
Payam Mohammadi's user avatar
6 votes
1 answer
2k views

I'm referring to "Fluent Python" by Luciano Ramalho. In chapter 12, there's a section "Coping with Multiple Inheritance" where the author suggests a few best practices, such as: ...
Lagerbaer's user avatar
  • 556
1 vote
2 answers
940 views

So, in general casting and dynamic_cast in particular are to be avoided. But I don't see a proper alternative for this: List<DerivedA*> ListA; List<DerivedB*> ListB; Bool Add(Base* obj) { ...
Philipp's user avatar
  • 21
-3 votes
3 answers
620 views

I came across a question earlier where someone asked how to create an array list with multiple object types (Create an ArrayList with multiple object types?). The easiest solution is to create a list ...
Chrisuu's user avatar
  • 123
0 votes
2 answers
271 views

Got a desktop application that interacts with some stateful third party web APIs. Its an interactive application, at some stages it has to halt execution and prompt for user input based on responses ...
boarnoah's user avatar
0 votes
1 answer
971 views

I am doing a project for a client where I am getting my first real heavy, hands-on exposure with Javascript. Since I have learned about adding .bind(this to callback functions, I find I am doing it ...
mydoghasworms's user avatar
3 votes
7 answers
455 views

Rewritten Question I appreciate the feedback and in response to that I'm re-writing my question. I can't give my specific situation (classes, etc), nor do I think that it would be helpful, as I work ...
timbo's user avatar
  • 149
1 vote
3 answers
795 views

Let's say I have a class that's a bit more than a pure Data object, i.e. it holds some data and some basic queries about that data. (In this case, it's a class representing a timetable) Now, I want ...
Lagerbaer's user avatar
  • 556
2 votes
1 answer
75 views

I'm doing some Java code practice to better understand the Single Responsibility Principle. Currently, I'm working with a network of data structures, where each structure implements an interface ...
MagerBlutooth's user avatar
2 votes
0 answers
129 views

We have a project that is meant to do signal processing. If all we had to do with the software was that one job, we would have a pretty clean architecture. Unfortunately, we've run into an issue most ...
Krupip's user avatar
  • 1,347
-1 votes
2 answers
107 views

I am rewriting a lexer class that has several "parameters" like whitespaceSplit. So it goes this way: lexer = new Lexer(); lexer.whitespaceSplit = true; lexer.otherParameter = ...; lexer.parse(file);...
porton's user avatar
  • 791
35 votes
9 answers
51k views

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 ...
Adam B's user avatar
  • 1,660
0 votes
1 answer
149 views

I want to know others opinion about this approach that I use in a lot of projects, for example, I can show the last time that I use it: public class DataStorageService { private enum Keys { ...
Tlaloc-ES's user avatar
  • 387
0 votes
1 answer
599 views

I have a doubt about if there are some recommendations for call directly an attribute in a class I think that in OOP you always should call an attribute by the get method. For example: On set ...
Tlaloc-ES's user avatar
  • 387
-1 votes
5 answers
357 views

In my current case, I've got two variables. Let's call them action and status for ease of use. They can have any value between 1 and 9. Depending on business logic, I've to either call subActionA() or ...
Yash Capoor's user avatar
10 votes
4 answers
3k views

I have the following code: public void moveCameraTo(Location location){ moveCameraTo(location.getLatitude(), location.getLongitude()); } public void moveCameraTo(double latitude, double ...
Tlaloc-ES's user avatar
  • 387
0 votes
1 answer
2k views

I have situation where in the Repository class I have a dictionary: Dictionary<TableName, Dictionary<EntityColumnName, SourceColumnName> map1 = new Dictionary<TableName, Dictionary<...
NSKBpro's user avatar
  • 219
2 votes
4 answers
182 views

Would you consider WHERE SomeDate <= '2018-01-01 23:59:59' instead of WHERE SomeDate < '2018-01-02' When the intention is that SomeDate goes no further then 2018-01-01 a code smell and if ...
axk's user avatar
  • 129
0 votes
5 answers
3k views

Let's say I use a Pair in this way: Pair<Long, Date> signup = getSignup(); System.out.println("User with ID " + signup.getLeft() + " signed up on " + signup.getRight()); Is it a form of ...
ddreian's user avatar
  • 111
5 votes
2 answers
561 views

I have a "tracker" class. This class tracks objects from a given input image. But in addition to this, there is another parameter that corresponds to a value used in generating the image. The ...
Krupip's user avatar
  • 1,347
3 votes
1 answer
1k views

I'm trying to make an abstract board game. In the game, a player can choose to make multiple actions within one turn such as placing, moving, or rotating a piece. I'm not sure if whether or not my ...
Michael Newgate's user avatar
-1 votes
1 answer
105 views

Most of my redux actions are 'fetch some data from the database, here's the authentication token', and they for the most part look the same, like this: action creator export const fetchDashboard = ...
dwjohnston's user avatar
  • 2,769
1 vote
1 answer
269 views

A long time ago I asked about using an enum to essentially use as a poor version of instanceof to make decisions about an object. As stated in this answer: When your weapon types enum just mirrors ...
user avatar
-1 votes
1 answer
149 views

I asked similar question earlier this morning, and for whatever reason, I'm not getting a complete answer to my question. I'll ask it a different way. I was attempting to understand Eric Lippert's ...
user avatar
2 votes
2 answers
221 views

I was reading on this SESE page about using a variable to indicate the object type, more specifically, an enum. The accepted answer states: When your weapon types enum just mirrors the class ...
user avatar
0 votes
2 answers
535 views

I'm not sure whether this qualifies as code smell, or if there may be some better way of performing the same task, but, basically, I want to format a 10 digit string, using C#, and have the following ...
Paul's user avatar
  • 201
3 votes
5 answers
1k views

The use of instanceof or getClass() is largely considered code smell. Is using a variable to indicate the type of object you're using also considered code smell? Suppose if I had an enum called ...
user avatar
0 votes
2 answers
182 views

So we're having a rather heated debate at work as to what would be the best practice going forward while refactoring our reporting system. Most of us have some strong opinions one way or the other, ...
JD Davis's user avatar
  • 1,387
18 votes
2 answers
19k views

Is it a code smell if the methods in my trait refer to parent::methods or to methods that are assumed to be in the utilising class? A random (senseless) example trait foo { public function bar() ...
Kamafeather's user avatar
4 votes
1 answer
10k views

Over many years, I always find myself reconsidering this design, so I wanted to get some feedback on my solution to it. Problem: I need a limited amount of objects = instances from a class, and I ...
Aganju's user avatar
  • 1,473