Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "enumerations"
-
Me: Bro look, I have learnt so many things from the past couple of days.
-Introduction
-Data Types
-Variables
-Arrays
-Operators
-Control Statements
-Classes
-Methods
-Inheritance
-Packages
-Interfaces
-Exception Handing
-Multi-threaded Programming
-Enumerations
-Autoboxing
-Annotations
-Generics
My senior: Congrats on finishing up the basics
Me: Those were just basics???...///!!! 😜3 -
Time for a soap box rant.
I just found this in one of our projects. I've simplified the example to make it more anonymous.
When I see code like this it automatically means there is a lack of attention to enumerations and/or understanding of what they are.
One may argue that in a certain execution of code it's a minor performance hit and therefore insignificant. It's still a performance hit. Furthermore, it takes even less time to do it the right way than it does to do it the wrong way.
Every one of these lines will enumerate the list from the beginning to try and find that one element you're interested in. Big O notation, people.
Throw that crap into a dictionary or hashset or similarly applicable data structure with direct reads at the beginning of your logic so that it only gets enumerated ONCE when the data structure instance is created. Then access it however many times you want.
Soap box rant over.15 -
Java apparently thinks it would be too convenient if we would use comparison operators on enumerations.
If you have to use the .ordinal() every time you want to do such a thing, you make the code uglier that you're trying to clean up to begin with!
Time to do this the hard way:
public static final int YELLING = 0;
public static final int SCREAMING = 1;
...1