Ranter
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
Comments
-
Generics are super as long as you only use them when needed. Don’t over do stuff with generics as you will end up in a big mess as you mentioned. I find them very useful when enforcing patterns or having a single implementation of a common functionality etc. But one thing I learned is that you overuse generics, you go in a rabbit hole sooner or later. If I can explain it with this example
Use generics to create signposts, traffic lights and rules on how to move around urban and rural areas, but leave the people choose on how to move around. It’s up to them to pick walking, cycling, using cars etc. Each transportation comes with its features and limitations defined by the generics. Anything more than that and we won’t have diversity of cars, bicycles and shoes -
@PappyHans wise words, you sound like a guru. I have definitely chained up the pedestrians and cars in my world. I cannot wait to spaghetti them out of their chains. Create a new better world and hopefully I never have to look back.
-
Gxost3014yGenerics add complexity to code so they must be used where their advantages overwhelm disadvantages. Once I wrote a generic class with a lot of type parameters, and it might look horrible to others. But. It allowed to implement similar behavior in many places and it's much easier to use it than to create a new implementation or copy-paste code.
Related Rants
Generics look kinda cool. But it doesn't takes long before it becomes a giant mess. And then a manager asks for some new functionality and you end up changing every class that inherits from it. I hate and love it at the same time. A confusing relationship.
rant
generics
inheritance