Hello! Why does the name of the
claim_free_popcorn! method end with
I was reading through the ruby style guide and it sounds like methods ending with
! are dangerous in some way (often modifying data or arguments in some way). From what I can see, there is nothing in the
claim_free_popcorn! method that would classify it as a dangerous method.
Thanks for any input on the subject.
The method when implemented raises an exception if the input doesn’t pass the validation. I personally would consider that a dangerous method because any callers need to handle that possibility at some level. A safer version of this method might return a boolean representing the popcorn being given. That wouldn’t impact code execution in the same way.
@BNAndras is correct, it is dangerous in that it may “crash” the program the user is writing, using this library, and so the
! is appropriate here.
Thanks for bringing this up by the way. It’s something I hadn’t noticed myself when I did the exercise recently.
(Sorry for the late reply)
Ok, that makes sense. Thanks for the input @BNAndras and @kotp .