[squeak-dev] Re: terse Object concatenation

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Wed Sep 22 20:38:40 UTC 2010


2010/9/22 Andreas Raab <andreas.raab at gmx.de>:
> On 9/22/2010 10:23 AM, Bert Freudenberg wrote:
>>
>> Stringification of any object in String>>, was only added last year. Until
>> then, there was no generic protocol involving #, it was only for special
>> classes (Collections, Exceptions, Sounds).
>>
>> It made (some) sense for Strings because it's just too convenient being
>> able to write ('the value is ', aNumber) without having to convert aNumber
>> to a String first.
>>
>> For making Arrays I prefer the brace notation. E.g. if you want to return
>> two objects from a method you still would need to write ^{a. b} because if
>> you write ^a,b would break if the first object happens to be a collection.
>> Also, brace notation is more efficient with more than 2 elements because it
>> avoids unnecessarily copying the intermediate collections.
>>
>> That said, I wouldn't really mind adding your feature.
>
> Same here. I'm not a strong proponent of object-object concatenation (though
> I *am* a strong proponent of string-object concatenation :-) but I don't
> mind it either. I can sort of see the appeal of writing "1, 2" but it's just
> something that I don't do often outside of literal string concatenation.
>

Oh, in a more popular language, I just saw some code like
   aString += anInt;
and started wondering what kind of tricky pointer arithmetic this would engage.
In fact, it was just an implicit concatenation, dumb me ;)
I thought I would have understood this pattern so much easily:
    aString += printString( anInt ); // excuse the smalltalkism here :)
I vote 99/1 for the later in this context.

In Smalltalk context maybe it's different, I understand 'abc' , 33 very well.

The problem is about common sense expectations / least surprising results.
For example, currently
   'abc' , $d -> 'abcd'
What would you decently expect from:
   $a , 'bcd' -> ?
Chris, ask your end users if they really understand why concatenating
a Character with a String should really answer an Array...
OK, OK, we might implement Character>>#, with a proper rule...

But then, where to stop ?
Following example was already used:
   #( 'one'  'two' ) , 'three'.
   'three' , #( 'two' 'one' ).
Probably none of the above will be of any use to, nor expected by any end user.
So the end user argument does not hold to my sense, except if , is
used in a restricted area, but then why implement it in Object ?

I also can understand the result of a message send is different
according to the receiver.
However using athe #difference: operator is a tricky argument :
concatenation is more akin to sum / union isn't it?.
Although not symetrical, I could decently expect it to be transitive. Like:
   self assert: (('abc' , $d ) , $e) = ('abc' , ($d , $e))

Plus some packages will insist on overriding #, to create a matrix, a
Float array, or something...

Plus the efficiency problem already stated (multiple copies).

All in all, I find the (a,b,c) notation very bright, seducing and
elegant, but also very deceiptive... It does not hold its promises.


Nicolas

> From my view brace syntax is slightly advantageous for complex constructs
> since it avoids additional parenthesis and can be indented properly as in:
>
>        self doWithArgs: {
>                self methodFoo: 42.
>                17 sqrt.
>                'Hello', 'World'.
>        }
>
> vs.
>
>        self doWithArgs: (self methodFoo: 42), 17 sqrt, ('Hello', 'World')
>
> But then again I really don't feel strongly about it.
>
> Cheers,
>  - Andreas
>
>



More information about the Squeak-dev mailing list