Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Prefixes _ and __ for object and class constants proposed

Reply
Thread Tools

Prefixes _ and __ for object and class constants proposed

 
 
Xeno Campanoli
Guest
Posts: n/a
 
      01-25-2008
I may have brought this up before, a long time ago, but something I want
is a prefix, like @ and @@, for constants that designates them as object
or class constants respectively. That way I could make a lot of things
constants that I am now just making variables and it would be obvious
that they are constants only available for that context. I really don't
like the underscore perfectly, but I've thought about it and it seems to
be the best choice of available characters. Has anybody every thought
about this (barring my possibly bringing it up two years ago), and does
anyone else think this is a reasonable suggestion? If so, I would think
it would be a small change that could be implemented in parallel with
existing prefix syntax handling.

Sincerely, Xeno Campanoli, Tacoma/Seattle programmer.
--
The only sustainable organizing methods focus not on scale,
but on good design of the functional unit,
not on winning battles, but on preservation.

 
Reply With Quote
 
 
 
 
Dave Thomas
Guest
Posts: n/a
 
      01-25-2008

On Jan 25, 2008, at 1:24 PM, Xeno Campanoli wrote:

> I may have brought this up before, a long time ago, but something I
> want
> is a prefix, like @ and @@, for constants that designates them as
> object
> or class constants respectively. That way I could make a lot of
> things
> constants that I am now just making variables and it would be obvious
> that they are constants only available for that context. I really
> don't
> like the underscore perfectly, but I've thought about it and it
> seems to
> be the best choice of available characters. Has anybody every thought
> about this (barring my possibly bringing it up two years ago), and
> does
> anyone else think this is a reasonable suggestion? If so, I would
> think
> it would be a small change that could be implemented in parallel with
> existing prefix syntax handling.


I'm not sure I've ever bumped into the need for an object constant,
but if I had, I'd probably have simply implemented an instance method

class Dave
def initialize(new_pi)
@pi = new_pi
end
def PI
@pi
end
end

d1 = Dave.new(3)
d2 = Dave.new(3.14159)
d3 = Dave.new(22.0/7.0)

puts d1.PI, d2.PI, d3.PI


Dave

 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      01-25-2008
On Jan 25, 2008, at 11:24 AM, Xeno Campanoli wrote:

> I may have brought this up before, a long time ago, but something I
> want
> is a prefix, like @ and @@, for constants that designates them as
> object
> or class constants respectively. That way I could make a lot of
> things
> constants that I am now just making variables and it would be obvious
> that they are constants only available for that context. I really
> don't
> like the underscore perfectly, but I've thought about it and it
> seems to
> be the best choice of available characters. Has anybody every thought
> about this (barring my possibly bringing it up two years ago), and
> does
> anyone else think this is a reasonable suggestion? If so, I would
> think
> it would be a small change that could be implemented in parallel with
> existing prefix syntax handling.



In ruby, constants are more like variables that yell at you.

$ ruby
X = 1
X = 2
p X
^D
-:2: warning: already initialized constant X
2


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using type prefixes with floating point constants Ioannis Vranos C Programming 4 03-27-2009 04:12 PM
Using type prefixes with floating point constants Ioannis Vranos C++ 2 03-27-2009 12:53 PM
Using type prefixes with floating point constants Ioannis Vranos C++ 0 03-26-2009 01:57 PM
proposed language extension: object state W Karas C++ 1 08-11-2008 05:37 PM
Proposed PEP: Treating Builtins as Constants in the Standard Library Raymond Hettinger Python 8 04-21-2004 11:31 AM



Advertisments