private variables 
Author Message
 private variables

Quote:
> > On a side note, I wish there were another symbol that could be
> > used in
> > place of _.  It makes variables look asymmetric (unless you write
> > _a_).

I might note that any variable name which isn't palindromic is
similarly asymmetric, no?  

Or do you actually only use palindromes?

=====
--
Use your computer to help find a cure for cancer: http://www.*-*-*.com/

Yahoo IM: michael_s_campbell

__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://www.*-*-*.com/



Wed, 02 Mar 2005 03:26:51 GMT  
 private variables

Quote:

> 1) The use of the keyword "private"
> Any methods defined after this keyword is private.  So probably we can
> make any new instance variables created after this keyword to be also
> private.  But mixing the private and non-private variables will be
> confusing.

private variables being differnt from local ones how? further can a
keyword like this work?. other keywords are just shorthands aren't they?
well, maybe it can.

Quote:
> 2) The use of a new symbol.

> "%" are used to denote the type of variables.  Ruby has used "$" and

> for private variables.

you see that's interesting. that's what i purposed for local variables
to end writer method ambiguities. ie. does x = 1 mean local variable x =
1, or self.x = 1.

-tom

--
tom sawyer, aka transami



Wed, 02 Mar 2005 03:53:29 GMT  
 private variables

Quote:

> Well, I am proposing 2 alternatives that I think is more consistent with
> the rest of Ruby.

> 1) The use of the keyword "private"
> Any methods defined after this keyword is private.  So probably we can
> make any new instance variables created after this keyword to be also
> private.  But mixing the private and non-private variables will be
> confusing.

I'd prefer having something explicit like:
  private_variables :some, :privvy, :vars, :listed, :here

And who knows, perhaps there is some magic tricks to be learned if
privateness can be dynamic and delayed. (I.e. define class, methods and
make instances, then pull a class_eval { private_variables :somevar })

Quote:
> 2) The use of a new symbol.

> "%" are used to denote the type of variables.  Ruby has used "$" and

> for private variables.


I can't think of any case where it would not be backwards compatible,
but I think it looks confusing:
        a = b%c  # b modulus c
        a = b %c # call method b with one argument; private variable c
But then, perhaps we have enough training dealing with this confusion
due to things like a +5 versus a+5...

Now, earlier when the talk of local variables came up, I noticed the
sign sitting to the left of the $ on my keyboard. The pound sign almost
looks like a L too! (L for local. ) Or maybe even , which looks like to
S's (supersecret perhaps). Don't take these ideas too serious though. I
do not prefer to program in ASCII art. :-)

--
(\[ 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___)



Wed, 02 Mar 2005 04:21:33 GMT  
 private variables
Hi,

Quote:

> private variables being differnt from local ones how? further can a
> keyword like this work?. other keywords are just shorthands aren't they?
> well, maybe it can.

I haven't really read the parser yet, but I imagine that after the
detection of keyword "private", the parser/interpreter will call
"rb_define_private_method()" instead of "rb_define_method()".  Therefore,
in a similar way, after the detection of the keyword "private", any newly

"rb_private_iv_set()" which just simply writes the data in a separate

it should invoke "rb_private_iv_get()" before searching using
"rb_iv_get()".

Quote:
> you see that's interesting. that's what i purposed for local variables
> to end writer method ambiguities. ie. does x = 1 mean local variable x =
> 1, or self.x = 1.

I must be missing something.  Why can "x = 1" imply "self.x = 1"?

Regards,

Bill



Wed, 02 Mar 2005 04:21:33 GMT  
 private variables

Quote:

> I'd prefer having something explicit like:
>   private_variables :some, :privvy, :vars, :listed, :here

> And who knows, perhaps there is some magic tricks to be learned if
> privateness can be dynamic and delayed. (I.e. define class, methods and
> make instances, then pull a class_eval { private_variables :somevar })

I am not an expert in Ruby parser/interpreter at all (let alone computer
science), but to me this seems perfectly doable.  I.e., after the
detection of keyword "private_variables", all public variables in the list
are moved from the current (public) instance variable hash to the private
instance variable hash.  And then writing and reading the instance
variables are like in my other post.

Quote:

> I can't think of any case where it would not be backwards compatible,
> but I think it looks confusing:
>    a = b%c  # b modulus c
>    a = b %c # call method b with one argument; private variable c
> But then, perhaps we have enough training dealing with this confusion
> due to things like a +5 versus a+5...

Well, "%" is also used in Perl as a modulus operator, and its use with
variables is fine there.  Like you have written above, we can make the
rule.  But probably people should write code in an explict way...

Regards,

Bill



Wed, 02 Mar 2005 04:33:47 GMT  
 private variables
Hi --

Quote:

> > 2) The use of a new symbol.

> > "%" are used to denote the type of variables.  Ruby has used "$" and

> > for private variables.


> I can't think of any case where it would not be backwards compatible,
> but I think it looks confusing:
>    a = b%c  # b modulus c
>    a = b %c # call method b with one argument; private variable c
> But then, perhaps we have enough training dealing with this confusion
> due to things like a +5 versus a+5...

Here's an non-backwards compatible case:

  %q__ = "some private thing"
  a = %q__

What's the value of a at this point?

Quote:
> Now, earlier when the talk of local variables came up, I noticed the
> sign sitting to the left of the $ on my keyboard. The pound sign almost
> looks like a L too! (L for local. ) Or maybe even , which looks like to
> S's (supersecret perhaps). Don't take these ideas too serious though. I
> do not prefer to program in ASCII art. :-)

I was musing before on '#', which has a secretive/private connotation,
as a variable prefix :-)  Thinking about these things makes one
increasingly grateful for the non-punctuation-riddenness of Ruby.

David

--
David Alan Black                      | Register for RubyConf 2002!


Web:  http://pirate.shu.edu/~blackdav | http://www.rubyconf.com



Wed, 02 Mar 2005 04:36:18 GMT  
 private variables

Quote:

> I haven't really read the parser yet, but I imagine that after the
> detection of keyword "private", the parser/interpreter will call
> "rb_define_private_method()" instead of "rb_define_method()".  Therefore,
> in a similar way, after the detection of the keyword "private", any newly

> "rb_private_iv_set()" which just simply writes the data in a separate

> it should invoke "rb_private_iv_get()" before searching using
> "rb_iv_get()".

i see. thanks.

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.

Quote:
> > you see that's interesting. that's what i purposed for local variables
> > to end writer method ambiguities. ie. does x = 1 mean local variable x =
> > 1, or self.x = 1.

> I must be missing something.  Why can "x = 1" imply "self.x = 1"?

no it can't which is exaclty what i mean becase any other method will
imply a self, EXCEPT the writer accessor method, unless of course the
local variable is define first. ex-

class It

  attr_accessor :x

  def seehere
    x        # same as self.x (self is implied)
    x = 10   # not the same as self.x=
    x        # no longer the same as self.x
  end

end

--
tom sawyer, aka transami



Wed, 02 Mar 2005 04:49:24 GMT  
 private variables

Quote:

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



Wed, 02 Mar 2005 04:55:23 GMT  
 private variables
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.

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

Regards,

Bill
===========================================================================

Quote:

> Here's an non-backwards compatible case:
>   %q__ = "some private thing"
>   a = %q__
> What's the value of a at this point?
> I was musing before on '#', which has a secretive/private connotation,
> as a variable prefix :-)  Thinking about these things makes one
> increasingly grateful for the non-punctuation-riddenness of Ruby.



Wed, 02 Mar 2005 04:55:51 GMT  
 private variables
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
============================================================================

Quote:


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



Wed, 02 Mar 2005 05:02:40 GMT  
 private variables
At Sat, 14 Sep 2002 06:22:55 +0900,

Quote:

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

-- Gotoken



Wed, 02 Mar 2005 06:05:06 GMT  
 private variables
oops, typo

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

Quote:

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

sub("omitted", "specified")
Quote:
> 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.



Wed, 02 Mar 2005 06:07:41 GMT  
 private variables

Quote:

> At Sat, 14 Sep 2002 06:22:55 +0900,

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

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?

--
tom sawyer, aka transami



Wed, 02 Mar 2005 06:16:47 GMT  
 private variables
At Sat, 14 Sep 2002 07:16:14 +0900,

Quote:

> 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
  private instance variable -> noninheritable instance variable

"private" sounds redundant and confusing, like "static" in C.

-- Gotoken



Wed, 02 Mar 2005 06:23:53 GMT  
 private variables
Hi --

Quote:

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

Quote:
> 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 :-)

David

--
David Alan Black                      | Register for RubyConf 2002!


Web:  http://pirate.shu.edu/~blackdav | http://www.rubyconf.com



Wed, 02 Mar 2005 07:39:09 GMT  
 
 [ 88 post ]  Go to page: [1] [2] [3] [4] [5] [6]

 Relevant Pages 
 

 
Powered by phpBB® Forum Software