3 ms·
`addable` might be too broad. It describes the implementation, but not the intent. If you know that x is only ever an int then you can safely change the implem
by duckerude 6y ago
`addable` might be too broad. It describes the implementation, but not the intent.
If you know that x is only ever an int then you can safely change the implementation to `return 2 * x`. Sometimes constraints give you extra possibilities.
- pansa2 6y agoI think this represents a difference in philosophy. I want to write functions once and use them wherever suitable, not write separate functions like twice_int, twice_string etc.
- duckerude 6y agoYou can write it for ints, figure out it's also useful for strings, and change the signature to also accept str. And then if you do ever want to change the implementation you can reason about the callers more easily and you won't have to create a new variant function for fear of breaking them. But perhaps that only makes sense for some functions. Probably not twice().