4

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.

Comments
  • 3
    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
  • 2
    @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.
  • 0
    Generics 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.
Add Comment