Re:Ruby type conversion
by dragonwriter on Sunday September 12, 2021 @10:33PM
(#28507274)
I disagree strongly with this:
> raise an error implicitly - effectively analogous to praying you get the right types
That's...not the case. Not explicitly testing or raising an error is neither “praying you get the right types” nor (as the piece later claims) the worst option, or leaving things to the next developer.
Its deferring type checking and error reporting (or type conversion) to some other method that the argument is passed to, and its absolutely what you should do 100% of the time instead of adding additional layers of redundancy if (1) you are passing the argument to a method that’s interface commits to the right type verification or conversion for the use case, and (2) you don't (in the case of error reporting) have a need to report errors differently than it will.
> raise an error implicitly - effectively analogous to praying you get the right types
That's...not the case. Not explicitly testing or raising an error is neither “praying you get the right types” nor (as the piece later claims) the worst option, or leaving things to the next developer.
Its deferring type checking and error reporting (or type conversion) to some other method that the argument is passed to, and its absolutely what you should do 100% of the time instead of adding additional layers of redundancy if (1) you are passing the argument to a method that’s interface commits to the right type verification or conversion for the use case, and (2) you don't (in the case of error reporting) have a need to report errors differently than it will.