Reply to Re: Butt ugly

Your name:

Reply:


Posted by Oli Filth on 05/29/06 03:40

Norman Peelman said the following on 29/05/2006 00:05:
> "Chung Leong" <chernyshevsky@hotmail.com> wrote in message
> news:1148841404.688262.297960@i40g2000cwc.googlegroups.com...
>> Norman Peelman wrote:
>>> The bottom line is this... precedence can only 'guess' so much as to
> what
>>> you the programmer wants and it normally does a great job. But when you
>>> start mixing two different functions ('.' and '+') it has to make
>>> assumptions, and those assumptions are to work on what is immediately
> known
>>> and that is what is to the immediate left and right:
>> I'm sorry but you're missing the entire point of the discussion. The
>> point is that the ambiguity is illogical and should not exist. To use
>> your terminology, apples are apples, oranges are oranges. Putting them
>> all in one bin and then guess at what you've got is stupid.
>>
>
> So, what would you want to happen? Should the parser go through each
> entire string looking for math equations first then string everything
> together after.

Who has suggested anything of the sort?


> The bottom line is that '.' and '+' are/were not really meant to be used at
> the same time as one works with strings and one works with mathematics.

Says who?


> So normally there would be no ambiguity.

There's no ambiguity; the behaviour is well-defined. However, there
*is* unintuitive behaviour.


> If you want:
>
> $a = 'If you multiply ' + 2 + 5 + 3 + ' by ' + 2 * 5 + ' you get ' + 10 *
> 10;
>
> then you're asking too much of one operator let alone the parser.

Assuming you mean "overload {+} to do both string concatenation and
addition", then you may well be right, it probably wouldn't be possible
to come up with a sensible precedence scheme so that the above example
gave the same result as:

$a = 'If you multiply ' . (2 + 5 + 3) . ' by ' . (2 * 5) . ' you get ' .
(10 * 10);

However, we're not talking about operator overloading. What we're
talking about is the operator precedence in PHP being unintuitive. If
there were an "intuitive" operator precedence (with {.} lower than
{+,-}), then the code below would give the same result:

$a = 'If you multiply ' . 2 + 5 + 3 . ' by ' . 2 * 5 . ' you get ' . 10
* 10;


--
Oli

[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

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