Instance variable capitalization


(Jim Freeze) #1

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


(Robert) #2

“Jim Freeze” jim@freeze.org schrieb im Newsbeitrag
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

(David A. Black) #3

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

David


David A. Black
dblack@wobblini.net


(Jim Freeze) #4

It just bugs me? :slight_smile:

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


Virtue is its own punishment.


(David A. Black) #5

But surely that’s a reason to avoid it :slight_smile:

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

It just bugs me? :slight_smile:


David A. Black
dblack@wobblini.net


(Jim Freeze) #6

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. :slight_smile:

···

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

It just bugs me? :slight_smile:

But surely that’s a reason to avoid it :slight_smile:


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


(Ara.T.Howard) #7

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

It just bugs me? :slight_smile:

But surely that’s a reason to avoid it :slight_smile:

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. :slight_smile:

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


(Tim Hunter) #8

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


(David A. Black) #9

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

It just bugs me? :slight_smile:

But surely that’s a reason to avoid it :slight_smile:

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. :slight_smile:

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


(David A. Black) #10

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


(Jim Freeze) #11

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


(Robert) #12

“Tim Hunter” Tim.Hunter@sas.com schrieb im Newsbeitrag
news:5sgc30lisd54n2gctuvv600ve07f3nhhcn@4ax.com

···

On Sat, 21 Feb 2004 00:56:00 +0900, Jim Freeze 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