3 ms·
What would be a real-world example of what you're referring to ("implement your own interfaces on built-in types")?
by benhoyt 6y ago
What would be a real-world example of what you're referring to ("implement your own interfaces on built-in types")?
- uluyol 6y agoPerhaps like overloading in C++? Hash functions are sometimes defined this way (https://abseil.io/docs/cpp/guides/hash#making-hashable-types https://abseil.io/docs/cpp/guides/hash#making-hashable-types)
- renewiltord 6y agoYou can do cool things like Ruby's `2.days.ago` in languages that allow you to implement traits on any type.
- dnr 6y ago`2.days.ago` is not "cool," it's an example of the some of the worst things about Ruby. Suppose I came across a cutesy expression like that in a program I was reading. How in the world am I supposed to figure out what code is invoked by that expression and where that code lives? It's emphasizing writeability over understandability, which is totally backwards from the point of view of engineering robust systems. Except it's barely even writeability, it's some bizarre notion that code should read like English where possible. And of course, since it's not actually English, it's only possible in limited ways and trying to generalize past those limits will break. So you have to learn exactly where the limits are anyway, which is as much effort as learning to use a proper library, except harder because a proper library will have the decency to stay in its own namespace.