You are here: Re: Butt ugly « PHP Programming Language « IT news, forums, messages
Re: Butt ugly

Posted by Norman Peelman on 05/28/06 16:46

"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:99c59$447987d8$8259c69c$5012@news1.tudelft.nl...
> 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.
>

But allowed in PHP, a loosely typed language giving great flexibility to the
programmer


> 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.
>

....there are two levels to the precedence rules and basically stated: when
to operators have equal precedence then left to right rules apply unless
otherwise noted.
see:
http://us3.php.net/manual/en/language.operators.php#language.operators.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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация