Professional Web Applications Themes

Instance variable capitalization - Ruby

I have a question about how ruby-like is it to capitalize instance variables. Often I think of the first character of an instance variable to be the first character following the '' sign. So, with this thinking, I am NOT inclined to use Foo, because I tend to think of it as a member form of Foo, which is a constant. So, although Foo is perfectly legal, I don't see it used much. Is there a good reason that I should avoid using capitalized instance variable names? -- "And what will you do when you grow up to be as ...

  1. #1

    Default Instance variable capitalization

    I have a question about how ruby-like is it to capitalize
    instance variables. Often I think of the first character
    of an instance variable to be the first character following
    the '' sign.

    So, with this thinking, I am NOT inclined to use Foo,
    because I tend to think of it as a member form
    of Foo, which is a constant. So, although Foo is perfectly
    legal, I don't see it used much.

    Is there a good reason that I should avoid using capitalized
    instance variable names?

    --
    "And what will you do when you grow up to be as big as me?"
    asked the father of his little son.
    "Diet."


    Jim Guest

  2. #2

    Default Re: Instance variable capitalization


    "Jim Freeze" <org> schrieb im Newsbeitrag
    news:org... 

    Isn't adherence to an informal convention reason enough? If it's so
    seldom used (though legal) it might surprise people who haven't seen it
    before and may make code harder to read.

    Just my 0.02 EUR...

    robert

    Robert Guest

  3. #3

    Default Re: Instance variable capitalization

    On Friday, 20 February 2004 at 23:00:58 +0900, David A. Black wrote: 

    It just bugs me? :)

    Personally, I have never used capitalized instance variables and I
    can't recall seeing it in any of the stdlibs. But while reviewing one of
    my colleague's code, I noticed that he had several instance
    variables that were capitalized. At first I thought, how is
    he not getting a constant warning. Then I realized that Ruby
    was ok with 'his' coding standard.

    So, one of the things I like about Ruby is that, for the most part,
    it keeps you from being stupid (e.g, making it obvious that
    instance variables are different from local variables, making globals
    and constants immediately recognizable, and so forth).

    But, allowing Foo is somewhat troubling to me since it 'feels' like
    a constant.

    --
    Virtue is its own punishment.


    Jim Guest

  4. #4

    Default Re: Instance variable capitalization

    On Saturday, 21 February 2004 at 0:49:49 +0900, David A. Black wrote: 
    > >
    > > It just bugs me? :)[/ref]
    >
    > But surely that's a reason *to* avoid it :-)[/ref]

    For me, but I don't think that will fly for everyone else
    in the company. I was looking for a more concrete reason.

    Surely you can come up with one David. :)


    --
    Hollywood is where if you don't have happiness you send out for it.
    -- Rex Reed


    Jim Guest

  5. #5

    Default Re: Instance variable capitalization

    On Sat, 21 Feb 2004, Jim Freeze wrote:
     
    > >
    > > But surely that's a reason *to* avoid it :-)[/ref]
    >
    > For me, but I don't think that will fly for everyone else
    > in the company. I was looking for a more concrete reason.
    >
    > Surely you can come up with one David. :)[/ref]

    class Foo
    Foo = 42
    attr :Foo
    def initialize
    Foo = Foo
    end
    end

    Foo.new.Foo::Foo ????


    -a
    --
    ================================================== =============================
    | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
    | PHONE :: 303.497.6469
    | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
    | URL :: http://www.ngdc.noaa.gov/stp/
    | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
    ================================================== =============================

    Ara.T.Howard Guest

  6. #6

    Default Re: Instance variable capitalization

    On Sat, 21 Feb 2004 00:56:00 +0900, Jim Freeze <org> wrote: 

    How about because using lowercase for instance variable names is a
    Ruby idiom?

    Here's a quote from _The Practice of Programming_ by Brian Kernighan
    and Rob Pike: "Like natural languages, programming languages have
    idioms, conventional ways that experienced programmers write common
    pieces of code. A central part of learning any language is developing
    a familiarity with its idioms."

    K. and P. go on to explain that _not_ respecting a language's idioms
    makes programs harder to understand and masks bugs. Therefore we
    should adopt recognized conventions instead of making up new ones.
    Tim Guest

  7. #7

    Default Re: Instance variable capitalization

    On Saturday, 21 February 2004 at 3:24:51 +0900, Tim Hunter wrote: 
    >
    > How about because using lowercase for instance variable names is a
    > Ruby idiom?
    >
    > Here's a quote from _The Practice of Programming_ by Brian Kernighan
    > and Rob Pike: "Like natural languages, programming languages have
    > idioms, conventional ways that experienced programmers write common
    > pieces of code. A central part of learning any language is developing
    > a familiarity with its idioms."
    >
    > K. and P. go on to explain that _not_ respecting a language's idioms
    > makes programs harder to understand and masks bugs. Therefore we
    > should adopt recognized conventions instead of making up new ones.[/ref]

    Thanks. I like that.

    --
    Maybe Computer Science should be in the College of Theology.
    -- R. S. Barton


    Jim Guest

  8. #8

    Default Re: Instance variable capitalization


    "Tim Hunter" <com> schrieb im Newsbeitrag
    news:com... 
    >
    > How about because using lowercase for instance variable names is a
    > Ruby idiom?
    >
    > Here's a quote from _The Practice of Programming_ by Brian Kernighan
    > and Rob Pike: "Like natural languages, programming languages have
    > idioms, conventional ways that experienced programmers write common
    > pieces of code. A central part of learning any language is developing
    > a familiarity with its idioms."
    >
    > K. and P. go on to explain that _not_ respecting a language's idioms
    > makes programs harder to understand and masks bugs. Therefore we
    > should adopt recognized conventions instead of making up new ones.[/ref]

    That was exactly what I tried to say. Thanks!

    robert

    Robert Guest

Similar Threads

  1. Assigning instance name to variable
    By bhenry17 webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 3
    Last Post: January 20th, 04:37 PM
  2. Capitalization of web form input
    By icrash2 in forum PHP Development
    Replies: 5
    Last Post: December 29th, 07:03 PM
  3. Replies: 2
    Last Post: December 23rd, 02:57 PM
  4. Forcing Capitalization in merged fields
    By Charlie in forum FileMaker
    Replies: 7
    Last Post: December 20th, 08:27 PM
  5. Capitalization of the first letter only
    By DJW in forum Microsoft Access
    Replies: 2
    Last Post: August 7th, 09:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139