[ale] Py[t]hon syntax (sic)
Benjamin Scherrey
scherrey at proteus-tech.com
Fri Jan 28 15:03:38 EST 2005
By default all members of a class are public in python, yes.
Unfortunately there is no concept like 'const' in C++ with python, just
the idiom of making a property with no set method established. However,
with the new decorator syntax recently introduced, it wouldn't be hard
to make a @const decorator that would throw an exception or something
when trying to write to that data. Unfortunately decorators can only be
applied to functions, as I understand them, so you'd still need to use
the property mechanism to establish it.
FWIW - the concept of 'const correctness' in C++ is one that I've
come to love and wish other languages would support it, especially
python. The other thing missing from python is a parameterized type
capability like C++ templates. You can fake it via the reflection
capabilities of python but you're gonna pay a performance penalty
whereas C++ templates are often a performance improvement.
-- Ben Scherrey
Michael Hirsch wrote:
><google_search ... read .. >
>
>Wow, that's pretty cool. Is there a way to do it where you don't have
>to write the getter/setter? So, if I'd like to have a variable exposed
>to read and write I don't need to do anything because by default
>everything is available outside the class. But if I want a read only
>member, I need to setup a reader methods and declare it. What I'd
>really like is declare a member read only, but not have to write
>accessor methods unless they are needed. I didn't see that mentioned in
>any of the docs. Did I miss it?
>
>Thanks,
>
>Michael
>
>
>_______________________________________________
>Ale mailing list
>Ale at ale.org
>http://www.ale.org/mailman/listinfo/ale
>
>
>
More information about the Ale
mailing list