Re: When is "z" != "z" ?

From: Date: Tue, 06 Jun 2006 13:46:09 +0000
Subject: Re: When is "z" != "z" ?
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-237456@lists.php.net to get a copy of this message
2006/6/6, Robert Cummings <robert@interjinn.com>:
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. You're right about ++ operator not to be considered a math operator, my
mistake. What I should have said is that the usual connotation and expected behaviour of ++ and the comparison operators is to give iteration capabilities to a certain data type, as used in a for statement. For that to happen certain constrains must be true for these operators, one of them being: any < ++any, which is not true for the way these operators behave in php. I'm not saying "It's wrong let's change it right away!", I completely agree that these rules can be bent on a not strongly typed language. The point I'm trying to make, the thing I want to understant without a trace of doubt, is: is it really worthy the functionality supplied with the string ++ operator as it is? I don't see its usefullness yet.

« previous php.general (#237456) next »