As reported elsewhere:
Begin forwarded message:
From: Florin Mateoc <florin.mateoc@gmail.com> Subject: [squeak-dev] #adaptToNumber:andSend: in String Date: 24 May 2015 22:04:21 CEST To: The general-purpose Squeak developers list <squeak-dev@lists.squeakfoundation.org> Reply-To: The general-purpose Squeak developers list <squeak-dev@lists.squeakfoundation.org>
Hi all,
Does anybody know why was the arithmetic protocol added to strings?
Evaluating '2' > 1 raises a DNU Evaluating 1 < '2' answers true. Even worse, 1 < '2bla' answers true as well.
This (the successful part) happens because of the implementation mentioned in the subject (plus numeric parser's behavior). That implementation was not part of the original protocol, as written by Dan Ingalls in 1998. It seems to have been added by Yoshiki in 2004. Was this done to address something in particular? To me it seems inconsistent, as in the above examples. There are other inconsistencies as well: the arithmetic operators mostly work - they were implemented in String by Yoshiki in 2004 as well, but e.g. 1s + '2' fails ('2' + 1s succeeds). And there is further funny behavior:
'2' + 1 evaluates to 3 '2' + '1' evaluates to '3' '2foo' + '1bar' evaluates to '3'
Presumably the failures could be made to work as well, but is this desirable? To me this seems as bad and arbitrary as Javascript's automatic conversions (there both comparisons mentioned above succeed, but 1 + '2' evaluates to '12' and '2' + 1 evaluates to '21', whereas 1 - '2' evaluates to -1 and '2' - 1 evaluates to 1. Just beautiful!).
Best, Florin
All this is just terrible, I knew there was some of this stuff in Pharo, but this is way worse than I expected it to be. And who uses this anyway ? Here are the mentioned expressions for easy copy/paste: '2' > 1. 1 < '2'. 1s + '2'. '2' + 1s. '2' + 1. '2' + '1'. '2foo' + '1bar'. Sven