4 ms·
> If you are making a list-like class because you need to keep a collection of strings which you are only comparing, don't use strings. Use <T> even if you only
by Nursie 6y ago
> If you are making a list-like class because you need to keep a collection of strings which you are only comparing, don't use strings. Use <T> even if you only use it with strings, the extra cost while creating the class is almost nothing, but the cost of a future refactorization will surely be greater.
Make it a little less readable for a future case you might never encounter?
- Twisol 6y agoI'm probably a bit of an outlier, but I do find it more readable to use type parameters instead of concrete types. If the type is opaque, I know the only ways to get or use values of that type are whatever explicit means the specifier of that type provides. This is less valuable the more specialized the type you're looking at -- generifying everything is just as much an antipattern as anything else -- but String is so widespread and abusable that it really is helpful to abstract over it in many circumstances.
- Nursie 6y agoEach to their own, as in so many ways. To me it becomes effectively another variable I have to track through the code and adds a small amount of extra cognitive load. Not a lot, of course, it's not a huge thing and I do use them where appropriate.