On Thu, Dec 1, 2011 at 9:15 PM, Kassym Dorsel <k.dorsel / gmail.com> wrote:

> Let's look at the Array class and start with method aliases.
>
> There are two aliases : .to_s <=> inspect , .size <=> .length , index
> <=> find_index. I understand the need for the first one, since sometimes
> the two don't return the same thing depending on the class. But why have
> size/length do the exact same thing..? This is one pretty intuitive so
> it's not that bad.h
>
> Then we have methods that are defined together, but with different names
> : collect <=> map , [] <=> slice <=> at.
>
> Next we have methods that seem to be doing the same thing, but are
> implemented differently : keep_if <=> select! , reject! <=> delete_if ,
> delete_at <=> slice! <=> shift
>
> Next are the nearly identical methods. They are the same except one does
> a little : count <=> length/size
>
> Useless methods? : replace. Why do you need an explicit method for this.
> Can't you just use the assignment operator ?
>
> These are just the ones I remember/found.  I'm sure there are many more
> examples in this class and others. Doesn't having multiple names for the
> same thing make it confusing when collaborating ? Is there any reason
> for this ? What is your take on the matter ?
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

IDK for all of them. Some are actually different, to_s and inspect are
quite different (and brillaint!).

Others like map and collect are that way in order to appeal to different
audiences. I think map comes from Lisp and Collect comes from Smalltalk. So
these are both common names for this method, and thus they are both
available. Same for size and length, and reduce and inject.

Others I think are synonyms either for convenience, or because they make
more sense in different contexts. I'd expect most of the operators are
defined for convenience (ie there is a method that does this, but b/c Ruby
allows operator overloading, they realize the operator would make a lot of
sense if it did this same thing, and are thus aliased).

Ruby generally adheres to TIMTOWDI, but I find I usually settle on a
preferred version, though it is sometimes fun to play with alternatives.