Style question

Discussion in 'Ruby' started by Bill Felton, Feb 25, 2011.

  1. Bill Felton

    Bill Felton Guest

    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=
     
    Bill Felton, Feb 25, 2011
    #1
    1. Advertising

  2. Bill Felton

    J. K. Guest

    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

    --
    Posted via http://www.ruby-forum.com/.
     
    J. K., Feb 25, 2011
    #2
    1. Advertising

  3. Bill Felton

    David Jacobs Guest

    [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,
    > 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
    >
     
    David Jacobs, Feb 25, 2011
    #3
  4. [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.
     
    Steve Klabnik, Feb 25, 2011
    #4
  5. Bill Felton

    koulikoff Guest

    On Feb 25, 3:28 pm, Bill Felton <>
    wrote:
    > 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.
     
    koulikoff, Feb 25, 2011
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Nicholson
    Replies:
    3
    Views:
    759
    Rob Nicholson
    May 28, 2005
  2. Replies:
    0
    Views:
    2,468
  3. Replies:
    1
    Views:
    796
    Bertilo Wennergren
    Nov 24, 2003
  4. Hardeep Rakhra
    Replies:
    8
    Views:
    645
    Hardeep Rakhra
    Jan 15, 2004
  5. Ken Varn
    Replies:
    0
    Views:
    479
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page