S
samppi
As a novice in Ruby, I love its elegance and consistence; it's now one
of my favorite languages. One of my favorite features is the practice
of ending the names of mutating methods with an exclamation point to
distinguish them from similar accessor methods, like "reverse" vs.
"reverse!"
I'm curious, though, about an apparent inconsistency with this rule in
Array: push, pop, shift, and unshift. All four methods modify objects
in-place, yet they don't have an "!". Why is this?
The only reason I can think of is that they lack "!"s in other
languages, which is a pretty tenuous reason at best--not many
languages name their methods "empty?" or "map!" instead of "is_empty"
or "map"...and in any case, Ruby is different enough in syntax and
style that it shouldn't even matter.
of my favorite languages. One of my favorite features is the practice
of ending the names of mutating methods with an exclamation point to
distinguish them from similar accessor methods, like "reverse" vs.
"reverse!"
I'm curious, though, about an apparent inconsistency with this rule in
Array: push, pop, shift, and unshift. All four methods modify objects
in-place, yet they don't have an "!". Why is this?
The only reason I can think of is that they lack "!"s in other
languages, which is a pretty tenuous reason at best--not many
languages name their methods "empty?" or "map!" instead of "is_empty"
or "map"...and in any case, Ruby is different enough in syntax and
style that it shouldn't even matter.