3 ms·
Maybe this is just me, but this suggestion seems worse than the problems def frobnicate(timeout: timedelta) -> None: ... timeout = timedelta(seconds
by some_random 5y ago
Maybe this is just me, but this suggestion seems worse than the problems
def frobnicate(timeout: timedelta) -> None:
...
timeout = timedelta(seconds=300)
frobnicate(timeout)
Now instead of remembering that frobnicate takes an argument of seconds, one now needs to remember it takes a completely different type, the constructor for which now also needs to be memorized. When the main problem presented is one of memorization, this seems obviously worse?
- belval 5y agoI suppose that it varies depending on the project/person, but I agree that using timedelta is less intuitive than just using seconds (as is done everywhere in Python).
- tehwebguy 5y agoYour editor will just tell you the type you need, no?
- AllegedAlec 5y ago> the constructor for which now also needs to be memorized This seems less like a memorisation problem and more of an IDE one. If I'm presented with a type in my IDE, I can just look through its constructors and methods to find the one I require; no need for memorisation.
- wpietri 5y agoThe problem is one of readability, not memorization. A lot of readability amounts to taking what the initial author already knows and expressing it so that it's easy for everybody who comes after to know too. Making implicit units explicit is a great example of that. Look at Martin Fowler's writings on Money types, for example. Or look at the $125 million failure of a space probe because people used implicit units: https://www.simscale.com/blog/2017/12/nasa-mars-climate-orbiter-metric/ https://www.simscale.com/blog/2017/12/nasa-mars-climate-orbi...