# Instance variable capitalization

**URL:** <https://rubytalk.org/t/instance-variable-capitalization/10246>\
**Category:** ruby-talk\
**Created:** [20 February 2004 13:42 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246 "2004-02-20T13:42:36Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [20 February 2004 13:42 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/1 "2004-02-20T13:42:36Z")

</div>

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.”

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [20 February 2004 13:59 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/2 "2004-02-20T13:59:51Z")

</div>

“Jim Freeze” [jim@freeze.org](mailto:jim@freeze.org) schrieb im Newsbeitrag  
[news:20040220134523.GA5668@freeze.org](mailto:news:20040220134523.GA5668@freeze.org)…

> 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?

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

```

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [20 February 2004 14:00 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/3 "2004-02-20T14:00:58Z")

</div>

Hi –

> **···**
>
> On Fri, 20 Feb 2004, Jim Freeze wrote:
> 
> > 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?
> 
> You’ve questioned its ruby-like-ness (correctly, I think), and  
> stated that you’re not inclined to use it, and that it isn’t  
> used much.
> 
> Is there any reason _not_ to avoid it? 🙂
> 
> David
> 
> –  
> David A. Black  
> [dblack@wobblini.net](mailto:dblack@wobblini.net)

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [20 February 2004 14:20 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/4 "2004-02-20T14:20:20Z")

</div>

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.

> **···**
>
> On Friday, 20 February 2004 at 23:00:58 +0900, David A. Black wrote:
> 
> > On Fri, 20 Feb 2004, Jim Freeze wrote:
> > 
> > You’ve questioned its ruby-like-ness (correctly, I think), and  
> > stated that you’re not inclined to use it, and that it isn’t  
> > used much.
> > 
> > Is there any reason _not_ to avoid it? 🙂
> 
> –  
> Virtue is its own punishment.

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [20 February 2004 15:49 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/5 "2004-02-20T15:49:49Z")

</div>

But surely that’s a reason _to_ avoid it 🙂

David

> **···**
>
> On Fri, 20 Feb 2004, Jim Freeze wrote:
> 
> > On Friday, 20 February 2004 at 23:00:58 +0900, David A. Black wrote:
> > 
> > > On Fri, 20 Feb 2004, Jim Freeze wrote:
> > > 
> > > You’ve questioned its ruby-like-ness (correctly, I think), and  
> > > stated that you’re not inclined to use it, and that it isn’t  
> > > used much.
> > > 
> > > Is there any reason _not_ to avoid it? 🙂
> > 
> > It just bugs me? 🙂
> 
> –  
> David A. Black  
> [dblack@wobblini.net](mailto:dblack@wobblini.net)

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [20 February 2004 15:56 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/6 "2004-02-20T15:56:00Z")

</div>

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. 🙂

> **···**
>
> On Saturday, 21 February 2004 at 0:49:49 +0900, David A. Black wrote:
> 
> > On Fri, 20 Feb 2004, Jim Freeze wrote:
> > 
> > > On Friday, 20 February 2004 at 23:00:58 +0900, David A. Black wrote:
> > > 
> > > > On Fri, 20 Feb 2004, Jim Freeze wrote:
> > > > 
> > > > You’ve questioned its ruby-like-ness (correctly, I think), and  
> > > > stated that you’re not inclined to use it, and that it isn’t  
> > > > used much.
> > > > 
> > > > Is there any reason _not_ to avoid it? 🙂
> > > 
> > > It just bugs me? 🙂
> > 
> > But surely that’s a reason _to_ avoid it 🙂
> 
> –  
> Hollywood is where if you don’t have happiness you send out for it.  
> – Rex Reed

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Ara.T.Howard](https://rubytalk.org/u/Ara.T.Howard)\
**Post date:** [20 February 2004 16:24 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/7 "2004-02-20T16:24:51Z")

</div>

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

Foo.new.Foo::Foo ???

-a

> **···**
>
> On Sat, 21 Feb 2004, Jim Freeze wrote:
> 
> > On Saturday, 21 February 2004 at 0:49:49 +0900, David A. Black wrote:
> > 
> > > On Fri, 20 Feb 2004, Jim Freeze wrote:
> > > 
> > > > On Friday, 20 February 2004 at 23:00:58 +0900, David A. Black wrote:
> > > > 
> > > > > On Fri, 20 Feb 2004, Jim Freeze wrote:
> > > > > 
> > > > > You’ve questioned its ruby-like-ness (correctly, I think), and  
> > > > > stated that you’re not inclined to use it, and that it isn’t  
> > > > > used much.
> > > > > 
> > > > > Is there any reason _not_ to avoid it? 🙂
> > > > 
> > > > It just bugs me? 🙂
> > > 
> > > But surely that’s a reason _to_ avoid it 🙂
> > 
> > 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. 🙂
> 
> # –
> 
> > EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov  
> > PHONE :: 303.497.6469  
> > ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328  
> > URL :: [Solar-Terrestrial Physics Data | NCEI](http://www.ngdc.noaa.gov/stp/)  
> > TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done  
> > ===============================================================================

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter3](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@Tim\_Hunter3](https://rubytalk.org/u/Tim_Hunter3)\
**Post date:** [20 February 2004 18:24 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/8 "2004-02-20T18:24:51Z")

</div>

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.

> **···**
>
> On Sat, 21 Feb 2004 00:56:00 +0900, Jim Freeze [jim@freeze.org](mailto:jim@freeze.org) wrote:
> 
> > For me, but I don’t think that will fly for everyone else  
> > in the company. I was looking for a more concrete reason.

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [20 February 2004 19:01 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/9 "2004-02-20T19:01:09Z")

</div>

Hi –

> > > > You’ve questioned its ruby-like-ness (correctly, I think), and  
> > > > stated that you’re not inclined to use it, and that it isn’t  
> > > > used much.
> > > > 
> > > > Is there any reason _not_ to avoid it? 🙂
> > > 
> > > It just bugs me? 🙂
> > 
> > But surely that’s a reason _to_ avoid it 🙂
> 
> 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. 🙂

I’m definitely an advocate of traditional Ruby style, and I like to  
use the Ruby source as the arbiter of style. Not that it’s absolutely  
uniform, but certain practices, such as avoiding camelCase for  
variable method names, are adhered to in the overwhelming majority of  
cases.

For your @Question we find:

$ egrep “(^|[^@])@[[:upper:]]” `find . -name "*.rb"` | wc -l  
186  
$ egrep “(^|[^@])@[[:lower:]]” `find . -name "*.rb"` | wc -l  
6438

So it’s not unheard of, but it’s very rare. Of the 186 @Upper ones,  
about 150 are in irb. I guess there’s some special case or need  
there.

David

> **···**
>
> On Sat, 21 Feb 2004, Jim Freeze wrote:
> 
> > On Saturday, 21 February 2004 at 0:49:49 +0900, David A. Black wrote:
> > 
> > > On Fri, 20 Feb 2004, Jim Freeze wrote:
> > > 
> > > > On Friday, 20 February 2004 at 23:00:58 +0900, David A. Black wrote:
> > > > 
> > > > > On Fri, 20 Feb 2004, Jim Freeze wrote:
> 
> –  
> David A. Black  
> [dblack@wobblini.net](mailto:dblack@wobblini.net)

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [20 February 2004 19:06 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/10 "2004-02-20T19:06:28Z")

</div>

> I’m definitely an advocate of traditional Ruby style, and I like to  
> use the Ruby source as the arbiter of style. Not that it’s absolutely  
> uniform, but certain practices, such as avoiding camelCase for  
> variable method names, are adhered to in the overwhelming majority of  
> ^^^^^^^^^^^^^^^^^^^^^^  
> variable and method names, …

> **···**
>
> On Sat, 21 Feb 2004, David A. Black wrote:
> 
> > cases.
> 
> –  
> David A. Black  
> [dblack@wobblini.net](mailto:dblack@wobblini.net)

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze2](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Jim\_Freeze2](https://rubytalk.org/u/Jim_Freeze2)\
**Post date:** [20 February 2004 19:10 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/11 "2004-02-20T19:10:02Z")

</div>

Thanks. I like that.

> **···**
>
> On Saturday, 21 February 2004 at 3:24:51 +0900, Tim Hunter wrote:
> 
> > On Sat, 21 Feb 2004 00:56:00 +0900, Jim Freeze [jim@freeze.org](mailto:jim@freeze.org) wrote:
> > 
> > > For me, but I don’t think that will fly for everyone else  
> > > in the company. I was looking for a more concrete reason.
> > 
> > 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.
> 
> –  
> Maybe Computer Science should be in the College of Theology.  
> – R. S. Barton

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [23 February 2004 08:29 UTC](https://rubytalk.org/t/instance-variable-capitalization/10246/12 "2004-02-23T08:29:52Z")

</div>

“Tim Hunter” [Tim.Hunter@sas.com](mailto:Tim.Hunter@sas.com) schrieb im Newsbeitrag  
[news:5sgc30lisd54n2gctuvv600ve07f3nhhcn@4ax.com](mailto:news:5sgc30lisd54n2gctuvv600ve07f3nhhcn@4ax.com)…

> **···**
>
> > On Sat, 21 Feb 2004 00:56:00 +0900, Jim Freeze [jim@freeze.org](mailto:jim@freeze.org) wrote:
> > 
> > > For me, but I don’t think that will fly for everyone else  
> > > in the company. I was looking for a more concrete reason.
> > 
> > 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.
> 
> That was exactly what I tried to say. Thanks!
> 
> ```
> robert
> 
> ```
