Albert Einstein said: "Everything should be made as simple as possible, but not more simple."
Your complaint does not make sense in the case of a dynamically typed language, so you should call it a reference to statically typed languages. In this case, your replacement example implicitly uses Generics (aka Template Classes), which means that whenever fun or gun , the new definition is based on the type of the argument. This can lead to dozens of additional methods, regardless of the programmer’s intentions. In particular, you are throwing away the benefit of compiler-type security checks for runtime errors.
If your goal was to simply pass an argument without checking its type, then the correct type would be Object not T
Type declarations are intended to simplify the life of a programmer by trapping errors at compile time, and not to fail at runtime. If your type definition is too complicated, you probably don’t understand your data. In your example, I would suggest adding fun and gun to MyClass instead of defining them separately. If fun and gun do not apply to all possible types of templates, then they should be defined in an explicit subclass, and not as separate functions that take a template argument of the class.
General concepts exist as a way to wrap behavior around more specific objects. List, Queue, Stack, these are great reasons for Generics, but at the end of the day, the only thing you should do with bare Generic is to instantiate this object and call methods on it. If you really feel the need to do more than using Generic, then you probably need to embed your Generic class as an instance object in a wrapper class that defines the behavior you need. You do this for the same reason that you insert primitives into the class: because numbers and strings alone do not convey semantic information about their contents.
Example:
What semantic information does the list convey? It’s just that you work with several triples of integers. On the other hand, List, where the color has 3 integers (red, blue, green) with limited values (0-255), conveys the intention that you work with several colors, but does not give any hints as to whether the List is ordered , allows you to duplicate or any other color information. Finally, the Palette can add these semantics for you: The palette has a name, contains several colors, but no duplicates and the order does not matter.
This has become a bit far from the original question, but for me it means that DRY (Do not Repeat Yourself) means indicating the information once, but this specification should be as accurate as necessary.