On Mon, Mar 03, 2008 at 07:20:05PM -0500, Alan G Isaac wrote:
On Mon, 3 Mar 2008, Gael Varoquaux apparently wrote:
* Type validation of attributes: the attributes of an object can be given a type descriptor (more precisely a validation method) and the compliance of the attribute is checked at run-time when this attribute is set. This is very useful for complex codebase, but probably not for you.
Can you easily state briefly how this differs from the use of properties (with type checking on the setter)?
Fundementaly, I don't think this differs much. You have a lot of syntactic sugar around it, which makes the code more readable, and easier to reuse, as it gives the commonly used patterns (dynamical initialisation, delegation, as well as a lot of existing validation types). Don't under-estimate the work to get the syntax and the different patterns right. When you use it a lot, Traits simply "feels right". I was present when someone asked R. Kern (I hope you won't mind me quoting you, Robert) "what do you use Traits for?", and his reply was, "As an 'object' replacement". In addition, the property-calling code is written in C, which makes it orders of magnitude faster than standard Python properties. Cheers, Gaƫl