Ruby and variable names

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

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.

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs