question of style

Paul Rubin http
Sat Jul 4 09:29:09 EDT 2009


aahz at pythoncraft.com (Aahz) writes:
> AFAICT, in order for Maybe and Option to work, you need to have some
> kind of static typing system.  Am I missing something?

I'm not sure.  Maybe there could be some kind of syntactic support in
a dynamic language (not that I'm suggesting adding that to Python).
I've been meaning to look up how Erlang does it.  For the limited
purpose of regexps that might or might not match, Perl has some
special support.

A kludgy Python counterpart to Option might be to use a pair (present, x)
where present is a bool saying whether the value is available.  If
present is True, then x is the value.  That could make it harder to
forget to test the flag before using the value.

In the stuff I'm doing, I often find it best to just use a list value,
so instead of:

     y = f(x) if x is not None else None

I can just write

     y = map(f, x)

In many cases it later turns out that list really was the natural
representation and it ends up growing additional potential elements.
I saw some article about database design recently that claimed as a
program evolves, all relationships end up becoming many-to-many.  It
gave as an example, if your program deals with names and addresses, it
will eventually have to handle the case where someone has more than
one residence address.



More information about the Python-list mailing list