[melbourne-pug] Coding idiom
Bill Birch
birchb at tpg.com.au
Mon May 8 15:23:17 CEST 2006
On Fri, 5 May 2006 10:57 am, Maurice Ling wrote:
>
> I am hoping that Bill's type system is able to strike a middle ground on
> this, allowing developers to define their own coding conventions which
> is mappable to a standard type system as metaknowledge, or something
> like that.
>
Hi,
A type system would help reason about the code. There's been various proposals
to add "interfaces" a la Java to Python. These have merit to solve this
issue. The technique is to first define an interface or interfaces, then the
implementation class methods or attributes that are not in in the interfaces
are effectively private. By declaring interfaces you are publically
committing to honour some methods, but caveat user on the others. Because
the interface is separated you don't have the issues with underscores in
names. The type system just allows you to capture the method signatures and
have code to introspect them at runtime.
Zope has an interface package which you can use right now. I have not used it
(yet). Has anyone? It looks clunky.
http://svn.zope.org/Zope3/trunk/src/zope/interface/README.txt?view=markup
You -could- use a decorator to scare people away:
def private(x) : return x
def protected(x) : return x
def public(x) : return x
class Ubeaut(object):
@private
def hairyDetailedFunctionNoOneShouldUse(self): pass
@public
def goForIt(self): pass
Not very original. But is blindingly obvious what you mean. If you stick with
this system one day you could code up something more snazzy than the identity
function.
Personally I am against using underscores to give subtle meanings, and I am
glad we have decorators. Perhaps one day the magic underscore behaviour of
import will be replaced with a decorator.
--
http://billbirch.wordpress.com/
More information about the melbourne-pug
mailing list