Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
unintuitive language feature (exclamation functions)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Gregory Brown, post: 4616341"] If the two were identical, why would we have both sub and sub! methods? The extra punctuation would be useless if it existed 'just for fun' The documentation for String#sub! is: "Performs the substitutions of String#sub in place, returning str, or nil if no substitutions were performed. " This has nothing to do with C. It has to do with interface design, and is meant to make things more intuitive, not less. Admittedly there is nothing inherently intuitive about some_method!, except that it might make you feel like you should pay more attention, like... Caution! Once learned, this convention can be very helpful. Since exclamation points are conventional and not behaviorly enforced in any way by Ruby itself, all ! methods should come with their own documentation. It does not necessarily mean 'modify the receiver in place', so further explanation is usually needed. Just remember that when you see foo and foo!, the latter is the one that the developer of the library you are using has indicated to require more attention, or be more specialized. If you're still not convinced, I recommend checking out a post by David Black on this topic, as it clearly explains the value of the convention: [URL]http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist[/URL] -greg [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
unintuitive language feature (exclamation functions)
Top