Thomas Adam
10/18/2007 10:58:00 AM
On 18/10/2007, arcadiorubiogarcia@gmail.com
<arcadiorubiogarcia@gmail.com> wrote:
> Hi all,
>
> I'm quite new to Ruby. One of the things I try to get when I learn a
> new language are naming conventions. I hate to write, for instance,
> Java code that looks like C++.
Heh. Not all of that is just down to naming conventions, of course.
What I sometimes do when I am switching to a new language is base a
sample program I might write in #{some_other_language} and then look
at making it more like that language. That said, I know a lot of
people who write perl code that looks like C. :P
> My question is: are Ruby's aliases intended for helping beginners
> coming from other languages, or you are truly free to choose any of
> the provided alternatives. For example:
It's not about helping the beginner, it's generally about your own
style which you might choose.
> is Enumerable#collect preferred over Enumerable#map
> or is Array#length preferred over Array#size ?
Either. They can be used interchangeably. I happen to prefer
Enumerable#collect, although you might (if you know perl, for
instance) prefer Enumerable#map.
The choice is yours. :)
Where the style counts more though is in terms of casing. So for instance:
* Constants start with a capital letter.
* Method names are in snake_case.
* Class names in CamelCase.
Etc, etc. Those sorts of idioms are probably the area you should
concentrate on.
-- Thomas Adam