Re: When is "z" != "z" ?
| From: | Robert Cummings | Date: | Tue, 06 Jun 2006 05:31:17 +0000 |
| Subject: | Re: When is "z" != "z" ? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237441@lists.php.net to get a copy of this message | ||
On Tue, 2006-06-06 at 00:01, Martin Alterisio wrote:
> > Because defining ++ and < and > in such a way as to make them "behave like
> > numbers" would have made them not work for alphabetizing. A string is a
> > string, and comparison of strings is alphabetic (for some definition of
> > alphabet). It's more useful to deal with strings as strings than to make
> > them quack like numbers.
> >
>
> Then, if it's not a math operation, why use a math operator for such
> functionality? In which way is the ++ operator that generates a string
I don't ever remember seeing ++ in math class. I do remember seeing it
in lots of computer classes and to that end it was "just an operator"
with whatever semantic meaning was applied to it for a given language. I
guess it's usually to increment an integer, but that's just "in
general". I mean if we want to get into "math" operators being used for
string purposes, then we should look at how many languages use the "+"
operator to concatenate two strings -- by your accounts they should
treat their operands as integers and do a rote addition.
> sequence, useful enough to justify the formal inconsistency between the math
> operators? I still don't see the advantages of having the ++ recognize the
> string as a sequence, and generate the next item in the sequence. I believe
> those decisions should be left to the coder, because he knows what the
> string really represents and which kind of sequence is being used.
In C++ they do leave it to the coder, and well, we all know what a mess
it can be deciphering overloaded operators in C++ (or maybe we ALL
don't). At any rate, the PHP overlords made a choice, and IMHO the best
choice. For such a fringe issue I don't see what the argument is all
about. If you want the functionality you get in C by incrementing a
char, then use the chr() function on an integer.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'