3 ms·
I miss generics, not because I would write new generic functions all the time, but because a few key generics provide infrastructure that increases the beauty o
by stcredzero 10y ago
I miss generics, not because I would write new generic functions all the time, but because a few key generics provide infrastructure that increases the beauty of programs dramatically.
The problem is this: Have you ever worked in a mature codebase with generics, where they haven't somehow been overused? Please tell me where that is!
- richard_todd 10y agoHaving personally fallen into the trap of overusing C++ templates on a project, I understand the point. However, I did not go on to reject the idea that templates should be in the language. Backing away from specific suggestions, I think it's healthy to recognize that Go has a boilerplate/DRY problem--not just with error handling!--, and it would be nice to address it in some way. If not with generics, then with something.
- pcwalton 10y agoI've also worked on codebases that have overused the && operator. Should we remove that in favor of nested if?
- stcredzero 10y agoOnly if the cost-benefit works out, and there isn't a better solution.
- pcwalton 10y agoAnd that's clearly the case with generics.
- stcredzero 10y agoYou're seriously saying that generically? All languages should simply have them? Not so sure you should dismiss the context like that.
- aikah 10y ago> You're seriously saying that generically? All languages should simply have them? Not so sure you should dismiss the context like that. Point me to a successful statically typed language born after 2005 that doesn't have some form of generics. Go has generics by the way, you just can define your own in user land, which is a stupid limitation.
- Someone 10y agoAlmost any powerful new feature in any language initially gets overused, but that isn't a reason to ban it. Class hierarchies, for example, got heavily overused before people discovered that composition most of the time is the better option, exceptions got overused before people learnt to only use them in exceptional cases, and dependency injection and XML (one of the first environments with strong support for it) got overused in Java programs. Generics are going the same way, if they haven't already (JavaScript modules will get there, too, but that seems at least a generation of programmers away) Also, the only difference I see between generics (with a bit of 'compile-time reflection') and go generate is that the former may be too magical for some, while the latter requires programmers to do more work (writing special comments to use existing functionality, and writing AST manipulation code to write new ones) and that it generates files only because the compiler wants to see them.
- wtetzner 10y agoOverused in what way? Do you have an example of what you mean by that? I'm having a hard time understanding where using generics would cause problems. C++ templates, sure, but those are much more powerful than just having parametric polymorphism.
- stcredzero 10y agoC++ templates, sure C++ templates! I keep on running into places where I'm debugging, then I find myself in a maze formed by template overuse, then debug around that instead. just having parametric polymorphism I think that could be workable in Go. I can imagine how debugging that would be straightforward.
- aikah 10y agoAs opposed to codebases that abuse interface {} and reflection ? I'd take the complexity of generics over this.
- runT1ME 10y agoYes, constantly. I've rarely seen generics overused.
- stcredzero 10y agoSend me contact info.