Confessions of a Python fanboy

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Jul 31 21:46:12 EDT 2009


On Fri, 31 Jul 2009 20:41:12 +0200, Emmanuel Surleau wrote:

>> We don't actually *declare* that something is constant and then have
>> that declaration ignored. Python doesn't lie to us, although (as in any
>> language) a programmer might.
> 
> You could say that Ruby doesn't either, 

Well you could say a lot of things. Admittedly you don't need a separate 
"constant" declaration, but creating a variable name with an initial 
uppercase letter is sufficient to make it a (supposed) constant:

irb(main):049:0* Thing = 5
=> 5
irb(main):050:0> Thing = 7
(irb):50: warning: already initialized constant Thing
=> 7

As you can see, Ruby (well, irb at least) considers that Thing is a 
constant, and then goes ahead and changes it anyway.

Apart from the use of an arbitrary naming convention instead of an 
explicit "make this constant" declaration, and the feeble way Ruby 
capitulates when you change it, I think having actual write-once 
constants is actually a plus.


> you just need to read the
> documentation. Ruby's unwritten motto is "flexibility über alles". In
> this regard, it is consistent (1). 

"It's consistent in its inconsistency" sort of thing perhaps?


> Not much is really bolted down in
> Ruby. You get encapsulation, but it's so easy to break that it's mostly
> symbolic. 

Out of curiosity, can you read/write class and instance attributes from 
outside the class without using a getter/setter?



-- 
Steven



More information about the Python-list mailing list