How to subclass Float class

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How to subclass Float class

HilaireFernandes
It looks like when I want to create a subclass of Float, I have this odd
class creation message. Moreoever, I can add instance variable to this
new class: when compiling there are wipe out: argument
instanceVariableNames: '' remain empty.

If I change Float to Object, all get back to normal.

Why is it like this ?


Float variableWordSubclass: #MyClass
        instanceVariableNames: ''
        classVariableNames: ''
        category: 'Cofigest-Financial'


Thanks

Hilaire

--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

stepharo
Hilaire

what is your requirement?

Stef

Le 10/1/15 22:52, Hilaire a écrit :

> It looks like when I want to create a subclass of Float, I have this odd
> class creation message. Moreoever, I can add instance variable to this
> new class: when compiling there are wipe out: argument
> instanceVariableNames: '' remain empty.
>
> If I change Float to Object, all get back to normal.
>
> Why is it like this ?
>
>
> Float variableWordSubclass: #MyClass
> instanceVariableNames: ''
> classVariableNames: ''
> category: 'Cofigest-Financial'
>
>
> Thanks
>
> Hilaire
>


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

HilaireFernandes
Le 11/01/2015 09:06, stepharo a écrit :
> Hilaire
>
> what is your requirement?
>
> Stef


I want to create a currency object, basically a Float with an attribute
to specify the currency unit.

Hilaire


--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

jtuchel
Hilaire,

unless you have very (very very) specific needs, I would strongly
discourage you to use Float for anything related to Money or Percentages.

We use a subclass of Object for MonetaryAmounts and implemented most of
the protocol of Magnitude. But, most importantly, the amount instVar is
made sure to always hold instances of ScaledDecimal (in VA Smalltalk,
that is).

Joachim

Am 11.01.15 um 10:25 schrieb Hilaire:

> Le 11/01/2015 09:06, stepharo a écrit :
>> Hilaire
>>
>> what is your requirement?
>>
>> Stef
>
> I want to create a currency object, basically a Float with an attribute
> to specify the currency unit.
>
> Hilaire
>
>


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

jtuchel
Ah, I just saw on second reading that you want to implement something
for currency exchange rates, not MonetaryAmounts. Still, don't use
Float, use ScaledDecimal or FixedPoint and make sure it NEVER contains a
Float. You'll get into all kinds of strange problems, starting with
Imports from datasources like Yahoo or whatever.

I'd subclass Object, and make the new class hold the exchange rates as a
ScaledDecimal with a well-defined scale (like 4 or 6 or even 8 digits if
you want).

Joachim




Am 11.01.15 um 10:28 schrieb Joachim Tuchel:

> Hilaire,
>
> unless you have very (very very) specific needs, I would strongly
> discourage you to use Float for anything related to Money or Percentages.
>
> We use a subclass of Object for MonetaryAmounts and implemented most
> of the protocol of Magnitude. But, most importantly, the amount
> instVar is made sure to always hold instances of ScaledDecimal (in VA
> Smalltalk, that is).
>
> Joachim
>
> Am 11.01.15 um 10:25 schrieb Hilaire:
>> Le 11/01/2015 09:06, stepharo a écrit :
>>> Hilaire
>>>
>>> what is your requirement?
>>>
>>> Stef
>>
>> I want to create a currency object, basically a Float with an attribute
>> to specify the currency unit.
>>
>> Hilaire
>>
>>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

jtuchel
There are more arguments against Subclassing any Number class:

Exchange rates are two-way most of the times. It is not only USD->EUR,
but also the other way round. This is not the responsibilty of a number.

For more information, I recommend Martin Fowler's Analysis Patterns book
(old, but not dated at all!).

Joachim


Am 11.01.15 um 10:31 schrieb Joachim Tuchel:

> Ah, I just saw on second reading that you want to implement something
> for currency exchange rates, not MonetaryAmounts. Still, don't use
> Float, use ScaledDecimal or FixedPoint and make sure it NEVER contains
> a Float. You'll get into all kinds of strange problems, starting with
> Imports from datasources like Yahoo or whatever.
>
> I'd subclass Object, and make the new class hold the exchange rates as
> a ScaledDecimal with a well-defined scale (like 4 or 6 or even 8
> digits if you want).
>
> Joachim
>
>
>
>
> Am 11.01.15 um 10:28 schrieb Joachim Tuchel:
>> Hilaire,
>>
>> unless you have very (very very) specific needs, I would strongly
>> discourage you to use Float for anything related to Money or
>> Percentages.
>>
>> We use a subclass of Object for MonetaryAmounts and implemented most
>> of the protocol of Magnitude. But, most importantly, the amount
>> instVar is made sure to always hold instances of ScaledDecimal (in VA
>> Smalltalk, that is).
>>
>> Joachim
>>
>> Am 11.01.15 um 10:25 schrieb Hilaire:
>>> Le 11/01/2015 09:06, stepharo a écrit :
>>>> Hilaire
>>>>
>>>> what is your requirement?
>>>>
>>>> Stef
>>>
>>> I want to create a currency object, basically a Float with an attribute
>>> to specify the currency unit.
>>>
>>> Hilaire
>>>
>>>
>>
>>
>>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

HilaireFernandes
Joachim,

Thanks for the tips.
I saw the Unit package was following the same pattern you are describing.
My first though was to use ScaledDecimal, but I discovered it is pretty
slow with computation (amortization schedule, search for rate) but there
are workarounds for that.

Hilaire

Le 11/01/2015 10:36, Joachim Tuchel a écrit :

> There are more arguments against Subclassing any Number class:
>
> Exchange rates are two-way most of the times. It is not only USD->EUR,
> but also the other way round. This is not the responsibilty of a number.
>
> For more information, I recommend Martin Fowler's Analysis Patterns book
> (old, but not dated at all!).
>
> Joachim
>
>
> Am 11.01.15 um 10:31 schrieb Joachim Tuchel:
>> Ah, I just saw on second reading that you want to implement something
>> for currency exchange rates, not MonetaryAmounts. Still, don't use
>> Float, use ScaledDecimal or FixedPoint and make sure it NEVER contains
>> a Float. You'll get into all kinds of strange problems, starting with
>> Imports from datasources like Yahoo or whatever.
>>
>> I'd subclass Object, and make the new class hold the exchange rates as
>> a ScaledDecimal with a well-defined scale (like 4 or 6 or even 8
>> digits if you want).
>>
>> Joachim
>>
>>
>>
>>
>> Am 11.01.15 um 10:28 schrieb Joachim Tuchel:
>>> Hilaire,
>>>
>>> unless you have very (very very) specific needs, I would strongly
>>> discourage you to use Float for anything related to Money or
>>> Percentages.
>>>
>>> We use a subclass of Object for MonetaryAmounts and implemented most
>>> of the protocol of Magnitude. But, most importantly, the amount
>>> instVar is made sure to always hold instances of ScaledDecimal (in VA
>>> Smalltalk, that is).
>>>
>>> Joachim
>>>
>>> Am 11.01.15 um 10:25 schrieb Hilaire:
>>>> Le 11/01/2015 09:06, stepharo a écrit :
>>>>> Hilaire
>>>>>
>>>>> what is your requirement?
>>>>>
>>>>> Stef
>>>>
>>>> I want to create a currency object, basically a Float with an attribute
>>>> to specify the currency unit.
>>>>
>>>> Hilaire
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
>
>


--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

stepharo
Hilaire

you have also acancagua that support unit and conversion and aconcagua
came out of a project dealing
with money and trades.

http://sdmeta.gforge.inria.fr/Teaching/CoursAnnecy/0506-M1-COO/
read the two articles in there.

Stef

Le 11/1/15 11:22, Hilaire a écrit :

> Joachim,
>
> Thanks for the tips.
> I saw the Unit package was following the same pattern you are describing.
> My first though was to use ScaledDecimal, but I discovered it is pretty
> slow with computation (amortization schedule, search for rate) but there
> are workarounds for that.
>
> Hilaire
>
> Le 11/01/2015 10:36, Joachim Tuchel a écrit :
>> There are more arguments against Subclassing any Number class:
>>
>> Exchange rates are two-way most of the times. It is not only USD->EUR,
>> but also the other way round. This is not the responsibilty of a number.
>>
>> For more information, I recommend Martin Fowler's Analysis Patterns book
>> (old, but not dated at all!).
>>
>> Joachim
>>
>>
>> Am 11.01.15 um 10:31 schrieb Joachim Tuchel:
>>> Ah, I just saw on second reading that you want to implement something
>>> for currency exchange rates, not MonetaryAmounts. Still, don't use
>>> Float, use ScaledDecimal or FixedPoint and make sure it NEVER contains
>>> a Float. You'll get into all kinds of strange problems, starting with
>>> Imports from datasources like Yahoo or whatever.
>>>
>>> I'd subclass Object, and make the new class hold the exchange rates as
>>> a ScaledDecimal with a well-defined scale (like 4 or 6 or even 8
>>> digits if you want).
>>>
>>> Joachim
>>>
>>>
>>>
>>>
>>> Am 11.01.15 um 10:28 schrieb Joachim Tuchel:
>>>> Hilaire,
>>>>
>>>> unless you have very (very very) specific needs, I would strongly
>>>> discourage you to use Float for anything related to Money or
>>>> Percentages.
>>>>
>>>> We use a subclass of Object for MonetaryAmounts and implemented most
>>>> of the protocol of Magnitude. But, most importantly, the amount
>>>> instVar is made sure to always hold instances of ScaledDecimal (in VA
>>>> Smalltalk, that is).
>>>>
>>>> Joachim
>>>>
>>>> Am 11.01.15 um 10:25 schrieb Hilaire:
>>>>> Le 11/01/2015 09:06, stepharo a écrit :
>>>>>> Hilaire
>>>>>>
>>>>>> what is your requirement?
>>>>>>
>>>>>> Stef
>>>>> I want to create a currency object, basically a Float with an attribute
>>>>> to specify the currency unit.
>>>>>
>>>>> Hilaire
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

HilaireFernandes
Very interesting reading.

The formula in figure 1 is wrong as it is "composed" interest, and power
should be used.

rate := 10 % / 1 year
terms := 6 months

100$ * (1 + rate) ^ terms

So I wonder how the simplification as exposed in Fig. 4 goes in that
case (rate should be transformed to 10/1200) and would be really
interested if the model can fit the real situation: how the model can
deduce rate per year should be adapted to rate per month without a prior
knowledge of the formula meaning.

In Smalltalkhub I see two Acomcagua packages, which one to use?


Hilaire


Le 11/01/2015 12:22, stepharo a écrit :

> Hilaire
>
> you have also acancagua that support unit and conversion and aconcagua
> came out of a project dealing
> with money and trades.
>
> http://sdmeta.gforge.inria.fr/Teaching/CoursAnnecy/0506-M1-COO/
> read the two articles in there.
>
> Stef


--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

stepharo
ask the authors they are both in the pharo mailing-list.

Le 11/1/15 16:25, Hilaire a écrit :

> Very interesting reading.
>
> The formula in figure 1 is wrong as it is "composed" interest, and power
> should be used.
>
> rate := 10 % / 1 year
> terms := 6 months
>
> 100$ * (1 + rate) ^ terms
>
> So I wonder how the simplification as exposed in Fig. 4 goes in that
> case (rate should be transformed to 10/1200) and would be really
> interested if the model can fit the real situation: how the model can
> deduce rate per year should be adapted to rate per month without a prior
> knowledge of the formula meaning.
>
> In Smalltalkhub I see two Acomcagua packages, which one to use?
>
>
> Hilaire
>
>
> Le 11/01/2015 12:22, stepharo a écrit :
>> Hilaire
>>
>> you have also acancagua that support unit and conversion and aconcagua
>> came out of a project dealing
>> with money and trades.
>>
>> http://sdmeta.gforge.inria.fr/Teaching/CoursAnnecy/0506-M1-COO/
>> read the two articles in there.
>>
>> Stef
>


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

HilaireFernandes
I hope the authors can see my question then. Anyway I will not use
Aconcagua for now because it is a bit overkill for my needs, I just
followed Joachim tips.

The Aconcagua package looks nicely designed and well test covered.

Thanks

Hilaire

Le 11/01/2015 21:03, stepharo a écrit :

> ask the authors they are both in the pharo mailing-list.
>
> Le 11/1/15 16:25, Hilaire a écrit :
>> Very interesting reading.
>>
>> The formula in figure 1 is wrong as it is "composed" interest, and power
>> should be used.
>>
>> rate := 10 % / 1 year
>> terms := 6 months
>>
>> 100$ * (1 + rate) ^ terms
>>
>> So I wonder how the simplification as exposed in Fig. 4 goes in that
>> case (rate should be transformed to 10/1200) and would be really
>> interested if the model can fit the real situation: how the model can
>> deduce rate per year should be adapted to rate per month without a prior
>> knowledge of the formula meaning.
>>
>> In Smalltalkhub I see two Acomcagua packages, which one to use?
>>
>>
>> Hilaire
>>
>>
>> Le 11/01/2015 12:22, stepharo a écrit :
>>> Hilaire
>>>
>>> you have also acancagua that support unit and conversion and aconcagua
>>> came out of a project dealing
>>> with money and trades.
>>>
>>> http://sdmeta.gforge.inria.fr/Teaching/CoursAnnecy/0506-M1-COO/
>>> read the two articles in there.
>>>
>>> Stef
>>
>
>
>


--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu


Reply | Threaded
Open this post in threaded view
|

Re: How to subclass Float class

stepharo

Le 12/1/15 09:54, Hilaire a écrit :
> I hope the authors can see my question then. Anyway I will not use
> Aconcagua for now because it is a bit overkill for my needs, I just
> followed Joachim tips.

why overkill you can just use what you need.

>
> The Aconcagua package looks nicely designed and well test covered.
>
> Thanks
>
> Hilaire
>
> Le 11/01/2015 21:03, stepharo a écrit :
>> ask the authors they are both in the pharo mailing-list.
>>
>> Le 11/1/15 16:25, Hilaire a écrit :
>>> Very interesting reading.
>>>
>>> The formula in figure 1 is wrong as it is "composed" interest, and power
>>> should be used.
>>>
>>> rate := 10 % / 1 year
>>> terms := 6 months
>>>
>>> 100$ * (1 + rate) ^ terms
>>>
>>> So I wonder how the simplification as exposed in Fig. 4 goes in that
>>> case (rate should be transformed to 10/1200) and would be really
>>> interested if the model can fit the real situation: how the model can
>>> deduce rate per year should be adapted to rate per month without a prior
>>> knowledge of the formula meaning.
>>>
>>> In Smalltalkhub I see two Acomcagua packages, which one to use?
>>>
>>>
>>> Hilaire
>>>
>>>
>>> Le 11/01/2015 12:22, stepharo a écrit :
>>>> Hilaire
>>>>
>>>> you have also acancagua that support unit and conversion and aconcagua
>>>> came out of a project dealing
>>>> with money and trades.
>>>>
>>>> http://sdmeta.gforge.inria.fr/Teaching/CoursAnnecy/0506-M1-COO/
>>>> read the two articles in there.
>>>>
>>>> Stef
>>
>>
>