-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion around the banning of alias
#377
Comments
The guide advises
This doesn't forbid you from using |
Indeed. More discussion on the subject can be found here. |
Then perhaps the guide needs elaboration. The way it's currently written implies that |
I was surprised to see the suggestion to avoid
alias
for no other reason thanalias_method
"will do," and I'm curious to hear what others think. In my experience, there are situations where each can be seen as clearer over the other.IMO, using
alias_method
is clearer and less ambiguous thanalias
—and sometimes the only possibility—when mutating class objects or singletons at runtime. There's a lot of discussion of this out there and, in fact, most proponents of avoidingalias
altogether point to these metaprogramming use cases.However, we're not always metaprogramming. Sometimes we're just linearly implementing methods and want to provide an alias method for whatever reason—perhaps the method is very generic and could conceivably be used in two semantically different ways (
inject
andreduce
come to mind) or maybe there are two forms but one seems more canonical and would benefit from a simpler name.Using
alias
here seems more appropriate because it's just more likedef
: 1) it's a keyword; 2) it's lexically scoped; 3) it's declaring a new identifier (not taking object arguments); and 4) it's short and sweet. Puttingalias_method
here instead would: 1) violate the rule of calling macros before instance method definition (it is indeed a macro in this context); and 2) look awkward due to the inconsistency between its symbol/string arguments anddef
's identifiers.Anyway, that's just my 2 cents and I'm curious about other perspectives on it.
The text was updated successfully, but these errors were encountered: