3 ms·
One potential downside is that it's a lot harder or more computationally expensive to figure out class/interface relationships in IDEs or other tools. (I haven'
by alangpierce 14y ago
One potential downside is that it's a lot harder or more computationally expensive to figure out class/interface relationships in IDEs or other tools. (I haven't used Go, though, so I'm not sure what kinds of tools are available for it.)
Generally, "what classes implement this interface?" is a question I need to ask quite a bit when working with Java in Eclipse. The simple way in Go (looking through all classes) would generate a bunch of false positives in a large enough codebase, and the more precise way (looking through all implicit casts everywhere to find all classes that are implicitly casted to the interface) is probably pretty slow or memory intensive and could potentially have false negatives (e.g. implementing classes that haven't been hooked up yet, and uses that aren't contained in your source tree).
There are other Eclipse operations that rely on this that would also be a lot harder to implement (in the same way they're implemented in Eclipse):
-"Find callers" on a class method includes calls to that method on superclasses and superinterfaces.
-"Rename method" automatically renames all methods with that name that are reachable through a path of implementer/interface relationships.
- danieldk 14y agoThere is another downside, and that is when interfaces are used to tag semantics. Say that I have classes that computes metric space distances. I could make an interface MetricSpace using a Distance method. However, in Go, every struct for which the Distance method is implemented with the same signature will implement the MetricSpace interface. In other languages with interfaces, only the types that are explicitly marked as implementing that interface will implement it.