Mat�as said:
...
> Let me put forth a proposal:
>
> - Numeric constants retain their characteristic type, that is: 5 is an
> Integer, 5.2 is a Double.
> - Addition, subtraction and multiplication of two Integers result in an
> Integer. Any other combination results in a Double. Division is
> *always* performed in floating-point (and returns a Double), even
> between two Integers.
> - Using a numeric reference in a template *always* results in a call to
> toString(); without involving any special formatting whatsoever. If
> finer control is desired, an explicit call to intValue() and/or the use
> of a tool will be necessary.
>
> Is this what you have in mind? If so, I'd like to make an addition to
> that:

These aren't bad rules, and I'd considered them also, but they're not what I
meant.  I meant that if any operation results in a mathematical whole
number, we ought to return an Integer (or Long if necessary).  If any
operation results in a value that is not a whole number, we ought to return
a Double.

Of course, you can argue that this might surprise someone (a type-familiar
java programmer) doing
#set( $foo = 1.2 + 1.8 )

but your proposal might equally surprise someone doing
#set( $foo = 9 / 3 )

i don't see a Perfect Way(tm).  both of our proposals are fairly simple and
i'd be fine with either, but i prefer mine (surprise, surprise!).  i think
your scheme is one well-suited to programmers familiar with numeric types.
we (as i'm one of that number) like to know what type we're getting back
from an operation.  but i don't like the type-ish stuff sneaking into the
templates like that.  i think in the templates numbers should just be
numbers and they should Just Work (tm).  given that, i think whole number
results should be returned as whole numbers (Integer) and so on.

> - Two new operators, \ (integer division) and % (integer modulus)
> operate on Integers (possibly converted from Doubles) and return an
> Integer *always*.

-1  \ and / are too close for easy identification.  i know that i, at least,
am sure to get them confused and be horribly annoyed.  also, i believe %
already exists (and i think that should be made to take doubles just like
the other existing operands).

no new operators please.

Nathan Bubna
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to