[squeak-dev] Re: terse Object concatenation

Bert Freudenberg bert at freudenbergs.de
Wed Sep 22 19:03:24 UTC 2010


On 22.09.2010, at 19:56, Andreas Raab wrote:

> 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.
> 
> 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')

Except that I know by looking at your first example that a 3-element-array will be passed. In the second case it depends on whether #methodFoo: returns a collection or not. If it does, this most probably does not what one would expect it to do.

- Bert -




More information about the Squeak-dev mailing list