On Oct 30, 11:29 am, Duncan Booth <[EMAIL PROTECTED]>
wrote:
> Neil Cerutti <[EMAIL PROTECTED]> wrote:
> > It's allows a standard programming idiom which provides a
> > primitive form of object oriented programming using closures to
> > represent state.
>
> > def account(opening_balance):
> >   balance = opening_balance
> >   def get_balance():
> >     nonlocal balance
> >     return balance
> >   def post_transaction(x):
> >     nonlocal balance
> >     balance += x
> >   return balance, post_transaction
>
> > fred_balance, fred_post = account(1500)
> > joe_balance, joe_post = account(12)
> > fred_post(20)
> > joe_post(-10)
> > fred_balance()
>
> TypeError: 'int' object is not callable
>
> > 1520
> > joe_balance()
>
> TypeError: 'int' object is not callable
>
> > 2
>
> > Python classes will of course nearly always win, though the idiom
> > looks like it might be faster (I don't have Python 3000 to try it
> > out).
>
> Python classes might be less error prone.

Why would using classes make your code any less prone to typographical
errors?

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to