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.
177 questions
8votes
5answers
4kviews
Is it still a code smell if a class knows all subtypes but not using instanceof and downcasting?
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(); } ...
3votes
4answers
600views
Why is "dependency injection" ok, but not "the opposite of preserve whole object (pass required parameters only)"?
According to Why should I use dependency injection?, "dependency injection" has some advantages, for example: "Non dependency injection" version: public class Client{ private ...
0votes
0answers
205views
Is "parallel composition hierarchies" a code smell?
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 ...
2votes
3answers
199views
Is it still "feature envy" if the state to make decision or the action to take after asking the state involves other classes to participate?
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: ...
6votes
4answers
1kviews
How to avoid init methods when 2 objects need the reference of each other?
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 ...
-1votes
4answers
341views
Is setting a flag in a loop a code smell?
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&...
0votes
3answers
354views
How to refactor "init()" into "physically make them two separate classes"?
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 ...
0votes
2answers
611views
Is it considered a code smell to not delete static pointers of a singleton?
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 ...
1vote
3answers
274views
What is the code smell called when API are encapsulated many times [closed]
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(...
0votes
6answers
1kviews
Is a static class full of static methods a code smell?
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 ...
1vote
3answers
2kviews
Are "Distributed Enums" an Anti-pattern in non-OOP like they seem to be considered in OOP?
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 ...
2votes
2answers
206views
Does using primitive types instead of user-defined types reduce dependencies?
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 ...
0votes
2answers
225views
Is it a code smell to put selection strategy concerns in an enum class?
Right now, I have this enum, called MemberCategory, defined to be: public enum MemberCategory { MEMBERSHIP("Membership"), GOLD_MEMBERSHIP("Gold"), SILVER_MEMBERSHIP(&...
0votes
1answer
88views
Better design for a REST import into web store
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 ...
4votes
4answers
2kviews
Is checking if a new GUID exists before insert a code smell?
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....