[Pharo-project] [squeak-dev] Re: Smalltalk string API

Bert Freudenberg bert at freudenbergs.de
Wed Feb 16 11:03:02 CET 2011

On 16.02.2011, at 10:39, Serge Stinckwich wrote:

> On Wed, Feb 16, 2011 at 4:24 PM, Nicolas Cellier
> <nicolas.cellier.aka.nice at gmail.com> wrote:
>> I started referencing Smalltalk idioms at
>> http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions)
>> I could have focused on ANSI but have chosen Squeak/Pharo. Feel free
>> to correct me and to complete me.
>> This is a very enlighting exercize, especially for pointing when API
>> turns to be not that bright.
>> During my perigrination, I notably noticed this:
>> #compare: returns 1, 2, or 3 : this is both very object oriented, very
>> intuitive and very standard and the rest of the world is stupid,
>> unless...
> Yes, really stupid, but maybe Squeak/Pharo should align here to the
> rest of the world or
> better, remove this method. We could use comparaison methods instead: <, >, ...

It is a low-level primitive, better indeed to use those operators instead, not call the compare* methods directly. For case-insensitive comparisons you should use e.g. caseInsensitiveLessOrEqual:.

If we want to provide a method that answers -1, 0, and 1 I'd leave the #compare: family alone, and instead add the operator <=> as in Ruby (which would be case-sensitive).

My 0.02€

- Bert -

More information about the Pharo-project mailing list