prePEP: Money data type

Batista, Facundo FBatista at uniFON.com.ar
Mon Oct 20 14:50:34 EDT 2003


#- Not at all: being able to delegate arithmetic issues to the 
#- "quantity"
#- object (Money in this case) is, on the contrary, crucial to simplify
#- higher application levels.  There IS a case for "money with currency
#- unit" to be separate from pure Money, basically to catch errors due
#- to trying to sum Euros and Dollars and the like; but that 
#- can be built
#- by subclassing a Money that's blissfully oblivious to currencies.  As
#- long as that Money CAN handle arithmetic, though; otherwise, what
#- ARE its responsibilities?!

By design, Money won't be conscious of currency, meaning that Money(2) are 2
dollars, 2 euros, or two argentinian pesos. 


#- > I prefer the idea of wrapping money in domain-specific ways, and
#- > leaving the money object relatively pure.
#- 
#- A relatively-pure object should generally have an area of 
#- responsibility
#- nevertheless.  I see Money's area of responsibility as 
#- arithmetic, and
#- rounding policy as being intrinsic to that.

Arithmetic is a *must to* in Money (as a decent numeric type). And rounding
is inseparable in arithmetic (anyway, everybody uses rounding when using
floating point).


#- Using the passed-in object's __class__ may be sufficient in 
#- that case,
#- and that should often be transparently achievable, as calling methods
#- on a money instance that return another new money instance should
#- automatically use the same class.  That's very easy too, 
#- e.g. consider
#- a very toy example, a meant-as-immutable Money that only holds an
#- amount and lets you sum a number to that returning a new instance:
#- 
#- class Money(object):
#-     def __init__(self, amount): self.amount = amount
#-     def __add__(self, other):
#-         return self.__class__(self.amount + other)

Very good idea, Alex. Any test case that test this?

.	Facundo





. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
ADVERTENCIA  

La información contenida en este mensaje y cualquier archivo anexo al mismo,
son para uso exclusivo del destinatario y pueden contener información
confidencial o propietaria, cuya divulgación es sancionada por la ley. 

Si Ud. No es uno de los destinatarios consignados o la persona responsable
de hacer llegar este mensaje a los destinatarios consignados, no está
autorizado a divulgar, copiar, distribuir o retener información (o parte de
ella) contenida en este mensaje. Por favor notifíquenos respondiendo al
remitente, borre el mensaje original y borre las copias (impresas o grabadas
en cualquier medio magnético) que pueda haber realizado del mismo. 

Todas las opiniones contenidas en este mail son propias del autor del
mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones
Personales S.A. o alguna empresa asociada. 

Los mensajes electrónicos pueden ser alterados, motivo por el cual
Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación
cualquiera sea el resultante de este mensaje. 

Muchas Gracias.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20031020/f98baabc/attachment.html>


More information about the Python-list mailing list