2 ms·
> I felt that "bang" methods should only be used for methods which mutate the receiver. I mentioned this upthread too, but it's a bit broader than that. Consid
by steveklabnik 10y ago
> I felt that "bang" methods should only be used for methods which mutate the receiver.
I mentioned this upthread too, but it's a bit broader than that. Consider http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-first http://api.rubyonrails.org/classes/ActiveRecord/FinderMethod... vs http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-first-21 http://api.rubyonrails.org/classes/ActiveRecord/FinderMethod... for example. The ! version raises an exception rather than return nil.
- hawkice 10y agoI actually like the ActiveRecord convention more than destructive-to-receiver -- it was even adopted by the elixir community (which makes even more sense than ruby, as there really aren't destructive updates in elixir).
- pmarreck 10y agoGood points. It would be great if there were two separately available suffixes, one to signify receiver mutation and one to signify raising vs nil. I certainly think Elixir went the right way here on the latter front (as it doesn't have to worry about receiver mutation).