Reply to Re: Butt ugly

Your name:

Reply:


Posted by Chung Leong on 05/28/06 19:23

Oli Filth wrote:
> Yes, but {+,-} are "related" operations, so you would perhaps expect
> them to have similar precedence. Equally, {*,/} are "related", but are
> "unrelated" to {+,-}. If {+,-,*,/} all had the same precedence, things
> would get messy and unintuitive. Similarly, as {.} is unrelated to any
> of them, you would expect it to have a different precedence, but instead
> it's given the same precedence as {+,-}.

"Related" is a loose term. The logical operators are sort of related
too, but they are have different precedence. One way to look at it is
that we want to preserve linearity at a given precedence level. Say we
have the express 1 + 3 - 5 + 7. We can think of it as the transform
(+3), (-5), and (+7) on the vector (1). These transforms can be applied
at any order. Likewise when we have 5 * 6 / 10, we can do either the
multiplication or the division first without affecting the result. Now
if we look at 0 & 0 | 1. Performing (&0) first yields 1, while doing
(|1) first yields 0.

> Personally, I don't find it a problem in practice, as I
> instinctively/automatically parenthesise anything where the precedence
> is hazy or unclear. However, I'd still be interested to know why the
> PHP developers thought that this choice of precedence made sense.

Probably has something to do with + being overloaded for strings in
PHP's early days. I don't see any harm though in splitting . out to its
own level. Who in their right mind would do a string concatenation only
to have the result destroyed by the math operation?

[Back to original 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

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