3 ms·
That's also a custom type. But for libraries, custom types for everything in interface definitions are problematic. Let's say you use library A which has some f
by flohofwoe 5y ago
That's also a custom type. But for libraries, custom types for everything in interface definitions are problematic. Let's say you use library A which has some functions that take a time delta, and another library B, that also has functions which take time deltas. Now both library would define their own time delta type, and you have two types for time deltas in your application and most likely need to add an additional 'meta time delta type' which can be converted to the library specific time deltas types. This will explode very quickly into lots of boilerplate code and is a good reason to use 'primitive types' in interfaces.
If you replace 'time delta' with 'strings' then the problem becomes more apparent. Each library defining its own string type would be a mess.
- geokon 5y agoIf you are working with a crappy language then that's probably true. But it doesn't have to be a lot of boilerplate and it can be local in scope. In Clojure it's a one-liner. (extend-protocol libA/stringable myLib/InputThing as-string [x] (myLib/to-string x) ) (libA/some-func (myLib/make-a-thing)) And sure it can just be doing something as simple as returning an internal value directly or calling some common stringifying method. You do have a good point that you may have redundant stringifying protocols across libraries - which sucks. > This will explode very quickly into lots of boilerplate code and is a good reason to use 'primitive types' in interfaces. I feel you were so close and missed :) The natural conclusion would be to have primitive interfaces - not primitive types. This way libraries only need to agree to adhere to an interface (and not an implementation)
- deleted 5y ago[deleted]