[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby and variable names

aidy

10/4/2006 10:10:00 AM

Hi,

I have noticed Ruby coders using 1 character variables names (e.g. t,d)

Is this done because Ruby is a dynamic language and any object can be
held in these variables?

aidy

3 Answers

Norgg

10/4/2006 10:25:00 AM

0

aidy wrote:
> Hi,
>
> I have noticed Ruby coders using 1 character variables names (e.g. t,d)
>
> Is this done because Ruby is a dynamic language and any object can be
> held in these variables?
>
> aidy
>

It's done mostly because of laziness, usually when you're just using the
variable for one or two statements after it's declared and then throwing
it away again, such as in an iterator or rescuing an exception.

Martin Coxall

10/4/2006 10:35:00 AM

0

> > I have noticed Ruby coders using 1 character variables names (e.g. t,d)
> >
> > Is this done because Ruby is a dynamic language and any object can be
> > held in these variables?

No. It's more an idiomatic aspect of good programming style. It's
commonplace to use single-char variables for short-lived throwaway
variables, such as loop counters, indexes and things like that, in
pretty much every language I've ever used.

Martin

MonkeeSage

10/4/2006 11:51:00 AM

0

Also note that code posted to newsgroups and mailing-lists is usually
not meant to be production quality; in that context many people use
single-letter variable names for brevity, where in production they
would follow the convention of writing self-documenting code.

Regards,
Jordan