On Saturday 01 August 2009 03:46:12 Steven D'Aprano wrote: > 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:
*shrugs* I see it as a way to encourage (but not force) people to follow a coding convention. Is this such a bad thing? > 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. I'm quite aware of how constants work in Ruby, yes :) > 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. Nothing wrong with naming conventions. This encourages a uniform coding style, something which Python could really use. > > 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? No, just consistent. > > 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? If you have an instance f class with a attribute @foo which doesn't have an accessor, you could do: f.instance_eval("@foo='bar'") And yes, instance_eval is evil. Cheers, Emm -- http://mail.python.org/mailman/listinfo/python-list