Private variables

Paul Brannan wrote:

···

On Mon, Sep 16, 2002 at 11:50:54PM +0900, Christian Szegedy wrote:

Private methods and class-local instance variables are quite different.
If you use a private method, you get an exception. If you try to use
a class-local instance variable then you just use another variable,
which could lead to obscure bugs.
So I think punctuation (and it should be as short as possible)
is a much better option.

If you try to use a class-local instance variable and it has not yet
been initialized, I would expect to see a warning when you run with ruby
-w, just like you get now with regular instance variables.

Paul

I often initialize instance variables conditionally. (That is, on first use).

Oh, yes, yes, but the distinction between ‘foo % bar’ and ‘foo %bar’ is
clear in Perl, isn’t it, independent of the definition of foo?

Regards,

Bill

···

===========================================================================
Marcin ‘Qrczak’ Kowalczyk qrczak@knm.org.pl wrote:

Sat, 14 Sep 2002 05:42:44 +0900, William Djaja Tjokroaminata billtj@z.glue.umd.edu pisze:

Well, “%” is also used in Perl as a modulus operator, and its use
with variables is fine there.

Well, the meaning of ‘foo % bar’ depends on whether foo has been
defined as ‘sub foo’ or ‘sub foo()’ :slight_smile:


__("< Marcin Kowalczyk
__/ qrczak@knm.org.pl
^^ Blog człowieka poczciwego.

Tue, 17 Sep 2002 23:33:46 +0900, William Djaja Tjokroaminata billtj@z.glue.umd.edu pisze:

Oh, yes, yes, but the distinction between ‘foo % bar’ and ‘foo %bar’ is
clear in Perl, isn’t it, independent of the definition of foo?

No, both can mean either foo(%bar) or foo() % bar(), depending on
the definition of foo.

···


__("< Marcin Kowalczyk
__/ qrczak@knm.org.pl
^^ Blog człowieka poczciwego.

Tom Sawyer wrote:

so were talking about instance variables being private? ugh, i’m
confused (sorry i didn’t catch the whole of this thread) arn’t instance
variable always private? you can only access them through accessor
methods. i’m missing somthing here.

They are object private, but not class private. (Puritans and C++
programmers would say they are “protected”, since the subclass can reach
them.)

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

Hi –

Hi,

I think you are right that “%X” sometimes is already special in Ruby (such
as %q, %Q, %w, %r, and %x). However, the use of “#” is really scary,
because it will make most, if not all, comments break down.

Oh, I know – I wouldn’t really advocate it. Actually I’m keeping my
fingers crossed that Ruby never gets any more punctuation prefixes on
variable names at all.

Hmmm, time to search other Perl symbols… how about "", anyone? Has
this symbol been used in Ruby?

Well, they don’t have to be “Perl symbols” specifically… but I hope
the point will turn out to be moot anyway :slight_smile:

David

···

On Sat, 14 Sep 2002, William Djaja Tjokroaminata wrote:


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Hi –

···

On Mon, 16 Sep 2002, Jim Freeze wrote:

David:

Did you ever find out how far from the SEA airport
to the conference center and hotel?

No… Can I punt this to the Seattle crowd? (Hey,
Seattle crowd, wake up – it’s 9:00 :slight_smile: I’ll try to
look it up if they don’t respond quickly.

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Hi,

Are we dead set against “attr_private” ?

class Foo
attr_private :bar
end

?

I’m not going to choose attr_private (unless someone put some idea in
my brain), because

a) we need static information about class local instance variable at
compile time. Dynamic attr_priate at run time is too late.

b) if we choose attr_private (by making it a syntax), we need to
search for declaration to distinguish whether a instance variable
is class local or not. I don’t feel it’s a Ruby Way ™.

						matz.
···

In message “Re: private variables” on 02/09/17, James F.Hranicky jfh@cise.ufl.edu writes:

It’s about 14 miles:

ddResults.py?proceed=Proceed&Pyt=Tmap&tarname=&tardesc=&newname=Seattle+
Tacoma+International+Airport&newdesc=&newHash=662400403&newTHash=-
629074884&newSts=&newTSts=&newFL=Use+Address+Below&newaddr=SEA&newcsz=Se
attle%2C+WA&newcountry=us&newTFL=Use+Address+Below&newtaddr=8th+and+Pike
&newtcsz=Seattle%2C+WA&newtcountry=us&Submit=Get+Directions

(UGLY URL!)

Please note that the destination address is approximate. It’s an
intersection near the convention center. Any taxi will know it by name.
A taxi will be your most expensive option (about $40-$50???) but is
readily available outside baggage claim.

Also, there is also the 194 bus that runs very frequently and during
the weekday goes through the city’s bus tunnel. The last stop going
north puts you at the Convention Center stop. It’s also the last stop
in the tunnel. Cost: $1.25-$2.50. Check
http://transit.metrokc.gov/bus/flymetro.html for exact details.

Finally (out of my reccomendations), there is shuttle express, which
you can get to by going to the parking garage outside the Sea-Tac
airport and going to the 3rd level. There should be signs for it. They
cost $22 door-to-door, run very very often any hour of the day, and (at
least going TO the airport) the second person is free. So gang up w/ a
fellow rubiest and split the cost!

···

On Monday, September 16, 2002, at 07:50 AM, Jim Freeze wrote:

Did you ever find out how far from the SEA airport
to the conference center and hotel?

It’s about 30 minutes call it 15 miles. SeaTac airport is in a suburb to
the south, and the conference center and hotels are in central Seattle.

-pate

···

On Mon, 16 Sep 2002, Jim Freeze wrote:

David:

Did you ever find out how far from the SEA airport
to the conference center and hotel?

Thanks


Jim Freeze

Programming Ruby
def initialize; fun; end
A language with class

Wait, wait, wait… I think someone should really have defined what
private variables in Ruby really are.

Using C++ terminology, I think the private variables in Ruby are really
like C++ “private” variables. In the current Ruby, instance variables are
always “protected”, and they can only be made “public” by the accessor
functions.

Regards,

Bill

···

============================================================================
Kent Dahl kentda@stud.ntnu.no wrote:

Tom Sawyer wrote:

so were talking about instance variables being private? ugh, i’m
confused (sorry i didn’t catch the whole of this thread) arn’t instance
variable always private? you can only access them through accessor
methods. i’m missing somthing here.

They are object private, but not class private. (Puritans and C++
programmers would say they are “protected”, since the subclass can reach
them.)

Hi –

···

On Tue, 17 Sep 2002 dblack@candle.superlink.net wrote:

Hi –

On Mon, 16 Sep 2002, Jim Freeze wrote:

David:

Did you ever find out how far from the SEA airport
to the conference center and hotel?

No… Can I punt this to the Seattle crowd? (Hey,
Seattle crowd, wake up – it’s 9:00 :slight_smile: I’ll try to
look it up if they don’t respond quickly.

OK, I guess they’re asleep :slight_smile:

The airport is 13 miles south of downtown Seattle, and travel to
downtown (depending on means) takes 25-45 minutes.

Thus spake
http://meetings.sixcontinentshotels.com/destinations/seattle/transport.html.

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

a private instance variable is one that is not inheritable. is that the
only difference?

using _@, or anyhting like that is pretty ugly. it would also make me
want to use _ in front of all my local variables, which take me back to
my old idea of using % for regular locals: then all variables would have
a puncutation mark in front of them.

$ - global
@@ - class
@ - instance
%@ - local instance
% - local

but % smacks of code breakage, unless it were optional.

what about using parentheticals instead? since currently it is pointless
to write: (@local). this may be a better notation.

just a thought.

-tom

···

On Mon, 2002-09-16 at 10:51, Yukihiro Matsumoto wrote:

Hi,

In message “Re: private variables” > on 02/09/17, James F.Hranicky jfh@cise.ufl.edu writes:

Are we dead set against “attr_private” ?

class Foo
attr_private :bar
end

?

I’m not going to choose attr_private (unless someone put some idea in
my brain), because

a) we need static information about class local instance variable at
compile time. Dynamic attr_priate at run time is too late.

b) if we choose attr_private (by making it a syntax), we need to
search for declaration to distinguish whether a instance variable
is class local or not. I don’t feel it’s a Ruby Way ™.

  					matz.


tom sawyer, aka transami
transami@transami.net

Are we dead set against “attr_private” ?

class Foo
attr_private :bar
end

?

I’m not going to choose attr_private (unless someone put some idea in
my brain), because

a) we need static information about class local instance variable at
compile time. Dynamic attr_priate at run time is too late.

b) if we choose attr_private (by making it a syntax), we need to
search for declaration to distinguish whether a instance variable
is class local or not. I don’t feel it’s a Ruby Way ™.

Hrm, this thread has been so huge that I’ve been in skim mode. I
understand that attr_private wouldn’t work because its dynamic and
determined at runtime, but I’m wondering if there isn’t another single
character that could be used in the grammar to designate a private
instance variable. I couldn’t think of any without there being some
kind of compile time declaration of a symbol… but there doesn’t
seem like there’s any way of providing compile time hints outside of
the special characters that get prepended to a symbol name. Just a
thought, but would it be possible to introduce a compile time syntax
for providing hints to the compiler? If so, then that’d likely open
up possibilities for other naming schemes. ::shrug:: Just my $0.02.
-sc

···


Sean Chittenden

Maybe the subject “private variable” is confusing. In Ruby, the
concept of “private” means “cannot be omitted its receiver”. But
there doesn’t exist receiver of a variable. In this sense, variable
is already “private”.

So, I’d like to propose new name
“nestable local variable” and “noninheritable instance variable”
to avoid confusion.

– Gotoken

···

At Sat, 14 Sep 2002 06:22:55 +0900, William Djaja Tjokroaminata wrote:

Wait, wait, wait… I think someone should really have defined what
private variables in Ruby really are.

Using C++ terminology, I think the private variables in Ruby are really
like C++ “private” variables. In the current Ruby, instance variables are
always “protected”, and they can only be made “public” by the accessor
functions.

Hi,

I think Matz is already deciding between “@_xxx” and “@__xxx”.

Regards,

Bill

···

==========================================================================
Sean Chittenden sean@chittenden.org wrote:
(deleted)

instance variable. I couldn’t think of any without there being some
kind of compile time declaration of a symbol… but there doesn’t
seem like there’s any way of providing compile time hints outside of
the special characters that get prepended to a symbol name. Just a
thought, but would it be possible to introduce a compile time syntax
for providing hints to the compiler? If so, then that’d likely open
up possibilities for other naming schemes. ::shrug:: Just my $0.02.
-sc


Sean Chittenden

oops, typo

Maybe the subject “private variable” is confusing. In Ruby, the
concept of “private” means “cannot be omitted its receiver”. But

sub(“omitted”, “specified”)

···

At Sat, 14 Sep 2002 07:04:36 +0900, GOTO Kentaro wrote:

there doesn’t exist receiver of a variable. In this sense, variable
is already “private”.

So, I’d like to propose new name
“nestable local variable” and “noninheritable instance variable”
to avoid confusion.

what do you mean by nested local variable? is that suppose to be the
same thing as noninheritable instance variable? or are you refering the
other kind of “private” variables ruby already has?

···

On Fri, 2002-09-13 at 16:04, GOTO Kentaro wrote:

At Sat, 14 Sep 2002 06:22:55 +0900, > William Djaja Tjokroaminata wrote:

Wait, wait, wait… I think someone should really have defined what
private variables in Ruby really are.

Using C++ terminology, I think the private variables in Ruby are really
like C++ “private” variables. In the current Ruby, instance variables are
always “protected”, and they can only be made “public” by the accessor
functions.

Maybe the subject “private variable” is confusing. In Ruby, the
concept of “private” means “cannot be omitted its receiver”. But
there doesn’t exist receiver of a variable. In this sense, variable
is already “private”.

So, I’d like to propose new name
“nestable local variable” and “noninheritable instance variable”
to avoid confusion.


tom sawyer, aka transami
transami@transami.net

  "nestable local variable"

Well, personnaly I'll call it "block local variable". For this reason

pigeon% ruby -e '_a = 12; 1.times { puts _a }'
-e:1: undefined local variable or method `_a' for #<Object:0x401bda4c> (NameError)
        from -e:1:in `times'
        from -e:1
pigeon%

The reason is that you can cut/paste the block and you have always the
same result : if the variable was assigned in the block ruby find it,
otherwise it try to call the method.

Guy Decoux

I meant change name. Not introducing other kind of variable.

private local variable → nestable local variable
private instance variable → noninheritable instance variable

“private” sounds redundant and confusing, like “static” in C.

– Gotoken

···

At Sat, 14 Sep 2002 07:16:14 +0900, Tom Sawyer wrote:

what do you mean by nested local variable? is that suppose to be the
same thing as noninheritable instance variable? or are you refering the
other kind of “private” variables ruby already has?

“GOTO Kentaro” gotoken@notwork.org wrote in message
news:200209132224.g8DMOBND083769@miso.k.notwork.org

what do you mean by nested local variable? is that suppose to be the
same thing as noninheritable instance variable? or are you refering the
other kind of “private” variables ruby already has?

I meant change name. Not introducing other kind of variable.

private local variable → nestable local variable

I tend to agree with Guy - block local variable'' is a more descriptive name for me. In fact, I probably would identify nestable local variable’’ to be the exact opposite of a
``block local variable’'.

private instance variable → noninheritable instance variable

“private” sounds redundant and confusing, like “static” in C.

I strongly agree with you - ``private instance variable’’
is terribly confusing - how about a
“class local instance variable”?

/Christoph

···

At Sat, 14 Sep 2002 07:16:14 +0900, > Tom Sawyer wrote:

– Gotoken