|
Posted by Rik on 05/28/06 14:22
Chung Leong wrote:
> Norman Peelman wrote:
>> It makes sense because as soon as you try to ADD a number to a
>> 'string' (or a 'string' to a 'string'), the strings are lost
>> (counted as zero):
>
> You might as well argue that 1 + 2 * 3 should equal 9. "As soon as
> you add 2 to 1, you get 3..."
>
> Addition and multiplication are communtative operations. 1 + 6 = 6 + 1
> and 2 * 3 = 3 * 2. Thanks to precedence, they maintains their
> properties in more complex expression: 1 + 2 * 3 = 1 + 3 * 2 = 3 * 2 +
> 1.
>
> In PHP, because . and + have the same precedence, addition is no
> longer communtative: "0." . 7 + 5 yields a different result from
> "0." . 5 +
> 7. So if you will, please explain how violating elementary
> mathematical principles makes sense.
Order matters, even in math.
5 - 7 != 7 - 5
Actually, '.' & '+' are kin of the same operator, but for different types.
It adds the piece on the right to the piece on the left. When '.', it
handles it like a string, when '+', it handles it like a number. We're back
to type juggling here, and using "0." as a string here is just making things
blurry.
Your reasoning has another flaw, for instance: in math '-' & '+' have the
same precendence, and you're actually saying:
2 + 2 - 3 (1)
should equal
3 - 2 + 2 (3)
or
2 - 3 + 2 (1)
depending on wether you decide the - or the + has precedence.
Thinking about it some more I think it boils down to this:
People know 'simple' symobls like * / + - form an earl age. Later on, they
will learn some more colpex opertors like log/ln/raising to a power.
For some bizar reason, they are not willing to accept a 'complex' operation
like 'take the literal symbolw of the right-part, and add those symbols to
the right of the left part' to be a dot (.), and they expect some kind of
precedence, while between / and * there is none, and + and - there is none,
and people just read from left to right.
Don't you think it's strange that when handling just strings, there is
little to no confusion, but as soon as number play a part all hell breaks
loose? It's just a lack of abstract thinking IMO.
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|