4 ms·
Implicit interfaces are the single best part of Go. And the “too much magic” comment is so misguided - author complains it is bad for large codebases but it’s
by s17n 9y ago
Implicit interfaces are the single best part of Go. And the “too much magic” comment is so misguided - author complains it is bad for large codebases but it’s exactly the opposite. In the real world everyone uses conventions like those enforced by Go’s so called magic. Having these built into the language means you don’t have to figure them out every time you look at a different programmer / team’s code.
- stouset 9y agoI repeatedly see this point re: implicit interfaces, and yet it’s never accompanied by an explanation of its actual benefits. The one defense I’ve heard is that it allows you to define interfaces that are implemented by types you don’t control, but this completely ignores the fact that doing so implicitly isn’t necessary for such a feature, and other languages (e.g., Rust) elegantly demonstrate why that is.
- bunderbunder 9y agoI'd go one further and say that the way other languages do it does a better job of letting you define interfaces for types you don't control. Sometimes the type you want to apply your interface/trait to doesn't have a function that does what you need, but could easily be assembled from other members of the type. And sometimes it does have a function that would work, except that the name is different. There's an Uncle Bob talk I watched a while back where he suggests that oftentimes language designers will say just about anything to avoid admitting that the real reason a feature is absent or was implemented in a hacky way is for the convenience of the compiler's authors.
- rcoveson 9y ago> Implicit interfaces are the single best part of Go. Help me understand this. The concern raised by the author regarding method signatures versus method contracts seems valid, and I have a hard time envisioning where implicit interfaces would be useful. Do you just hope to get lucky? Somebody, without knowing about the interface, would have to use all the same parameters and return types, the same method name, and implement the contract in a compatible way for it to work, right?
- andrewprock 9y agoImplicit interfaces reduces compile time dependencies. One of the original target features of Go was that it wouldn't take forever to compile Google-scale programs, like C++ does.
- stouset 9y agoGP claimed that this feature is the "single best part of Go".