Style question

B

Bill Felton

Hi all,
Quick (I hope) question about preferred style for variable naming. I =
see reference in various books to a preferred Ruby style of underscores =
in variable names in preference to camel case. =
(my_variable_has_this_name vs myVariableHasThisName).
Why?
Two reasons I ask, a better one and a poorer one. The poorer one is =
that I come from Smalltalk where camel case is standard and expected.
The better one is that camel case seems easier to type, the shift key =
being both easier to reach and 'more familiar' to the hands than the =
underscore.

Thanks!

Bill=
 
J

J. K.

hi Bill -

i use camelCase too, and if i'm not mistaken this is strictly a
question of style preference. from what i understand most rubyfolk use
underscores, but i don't believe it really matters.
couldn't agree more that the shift key is quicker, and i just like the
way camelCase looks better...
all_those_underscores_get_funny_looking_to_me.

-jk
 
D

David Jacobs

[Note: parts of this message were removed to make it a legal post.]

I guess Matz could speak to this better than I can, but I think that underscores are an aesthetic choice. They aren't necessarily a pragmatic one, re: strokes involved. Because the underscores are an aesthetic choice, there is no rational way of demonstrating that they're better.

However, consider that:

1. Underscores give variable names a flow - they don't disrupt the code around them
2. Underscores mirror standard English prose: it's easy to read underscored variables "without the underscores":

Consider:

def render(results)
# render results
end

resultsNeedRendering = true
render results if resultsNeedRendering

results_need_rendering = true
render results if results_need_rendering

I can tell you anecdotally that 6 years ago, moving from Java, I was very opposed to snake_case. Now, I can't imagine going back to camelCase.

David
On Friday, 25 February 2011 at 7:28 am, Bill Felton wrote:
Hi all,
 
S

Steve Klabnik

[Note: parts of this message were removed to make it a legal post.]

Also remember that "standard Ruby Style" has class names with multiple
worlds in CapCamelCase, so using underscores_for_variables helps distinguish
the two.
 
K

koulikoff

Hi all,
Quick (I hope) question about preferred style for variable naming.  I see reference in various books to a preferred Ruby style of underscores in variable names in preference to camel case.  (my_variable_has_this_name vsmyVariableHasThisName).
Why?
Two reasons I ask, a better one and a poorer one.  The poorer one is that I come from Smalltalk where camel case is standard and expected.
The better one is that camel case seems easier to type, the shift key being both easier to reach and 'more familiar' to the hands than the underscore.

Thanks!

Bill

Rails standard uses underscore. As for my preference I like it too
especially after migrating from qwerty to azerty layout since the
latter does not require shift for underscore.
 

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

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top