ruby and variable names

A

aidy

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
 
J

John Turner

aidy said:
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.
 
M

Martin Coxall

I have noticed Ruby coders using 1 character variables names (e.g. t,d)
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
 
M

MonkeeSage

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,214
Messages
2,571,112
Members
47,704
Latest member
DavidSuita

Latest Threads

Top