The Voidspace Techie Blog

Haha, love it!


Isn't typing so '70's'? More seriously, I'm not arguing that typing itself is an always bad thing, but how about something more, like a "specification".

def some_function(name):
....require(name, pattern('a-zA-Z'))

or better

class Category:
....name_is = spec(
........both(string, ........pattern('a-zA-Z')),
........"a character-only, human readable name")
....description = spec(
........either(None, string),
........"description of the category")

....def __init__(name, description=None):
........specify(self,
............name=name,
............description=description)

I can see strong type checking being useful at times, but I find that in practice this pattern, which gives much more than simple type checking, meets my needs very well indeed.

One module, depends on nothing from the package it lives within:

http://www.mems-exchange.org/sof...1.8/lib/ spec.py


Gravatar A framework exists to do such typing. It is called Traits, http://code.enthought.com/traits/ . I strongly advise people to have a look at it, it can be very useful because it implements an MVC (Model View Controller) based on the typing of attributes of an object. Definitly a must for python programmers wanting to manipulate objects with attributes set throught user interaction.


Gravatar Only later did it occur to me that fuzzy was probably joking


Gravatar


Gravatar You're harsh! I recently wrote some code that followed this pattern, though it wasn't quite as severe:

//if you alter this variable without calling message(), a kitten will die
var _messageStr = '';


Name:

Email:

URL:

Comment:  ? 

 

Commenting by HaloScan