terse Object concatenation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
27 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: terse Object concatenation

Chris Muller-3
> 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...

$a , 'bcd' is no different than what they should decently expect from:

  { $a }, 'bcd'

Any guesses?  It's the same answer.  It's consistent, and not just in
the answer but in the way it is equally "non-obvious".  But I know you
aren't going to protest concatenation of an Array of Characters with a
String on those grounds.

These sorts of questions are irrelevant for the real-world scenario
anyway.  You all are critiquing on the wrong criteria.  You are
looking for some obscure way to mix a String, what we all know to be a
special kind of Collection with special behaviors, with another kind
of objects in order to "look for something non-obvious".  C'mon now...

The fact is that heterogeneous collections are a rarity in real-world
applications, but this is even a subset of those cases!  e.g., this is
some hypothetical heterogeneous collection of Strings, Objects,
Characters that was "accidently" created by some junior programmer,
because he used concatenation and it gave results he didn't expect
(but should have), and he didn't test it and so planes fell out of the
sky.  Ohhh, the humanity of it!"  :-)

I guess I'm feeling frustrated by having to fight so hard against all
of these fake "problems" for a enhancement has absolutely _no bearing_
on any of your lives, but tangibly important for my application and
users.  It's just a simple way for them to express a list of objects
in a natural way that can be directly interpreted.  Nothing more.

I think you all should let me have this.  If you don't use it, it
can't affect you.  We haven't run across a regression in the five
years we've had this in our images, but if we do, I'll certainly fix
it....



> 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
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: terse Object concatenation

Randal L. Schwartz
>>>>> "Chris" == Chris Muller <[hidden email]> writes:

Chris> I guess I'm feeling frustrated by having to fight so hard against all
Chris> of these fake "problems" for a enhancement has absolutely _no bearing_
Chris> on any of your lives, but tangibly important for my application and
Chris> users.  It's just a simple way for them to express a list of objects
Chris> in a natural way that can be directly interpreted.  Nothing more.

OK, then add an override in your packages.  I just don't want it in
core.

It's too much dwimmery, in the same sense that I would object to
nonBooleans all of a sudden being treated as true or false instead of
rejecting them with MustBeBoolean, just because Ruby and Perl work that
way. It doesn't feel like Smalltalk any more.

It would also have to be special cased for anything that wants to be
portable with the other Smalltalks.  Ugh.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Reply | Threaded
Open this post in threaded view
|

Re: terse Object concatenation

Miguel Cobá
In reply to this post by Chris Muller-3
Hi Chris,

just my opinion here.

Indeed the proposed code could be useful for developers. Some thing that
I think is important is that when something is in the core image, it is
an endorsement for use it. So, this change even isn't really a syntax
change of smalltalk, in practice it is. Is some new syntax to write
arrays. This gives the promise that can be used everywhere without
adverse effects (like the ones others have highlighted), with uniformity
in its usage and generally a good practice in smalltalk.
Now this is not portable, because it will be only in Squeak, so if code
begin to use it it will contain unportable code that will need to be
changed, effectively reverting to a portable syntax and in fact putting
aside your concatenation code.
Also, you said that is for end users, and I think that you said
non-developer users, but if that is the case, then why don't add this as
part of the application are using, so that takes the input of the user
and transform it to the underlying, portable, historical syntax, all
transparent to the user.
Now, if they are programming, then I think that they must now the real
syntax and that they are using a facility provided by its application
and not by the language.

Summary, I think that this belongs to a specific application code and
not to the Squeak code base.

Just my opinion.

Cheers


El jue, 23-09-2010 a las 14:07 -0500, Chris Muller escribió:

> > 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...
>
> $a , 'bcd' is no different than what they should decently expect from:
>
>   { $a }, 'bcd'
>
> Any guesses?  It's the same answer.  It's consistent, and not just in
> the answer but in the way it is equally "non-obvious".  But I know you
> aren't going to protest concatenation of an Array of Characters with a
> String on those grounds.
>
> These sorts of questions are irrelevant for the real-world scenario
> anyway.  You all are critiquing on the wrong criteria.  You are
> looking for some obscure way to mix a String, what we all know to be a
> special kind of Collection with special behaviors, with another kind
> of objects in order to "look for something non-obvious".  C'mon now...
>
> The fact is that heterogeneous collections are a rarity in real-world
> applications, but this is even a subset of those cases!  e.g., this is
> some hypothetical heterogeneous collection of Strings, Objects,
> Characters that was "accidently" created by some junior programmer,
> because he used concatenation and it gave results he didn't expect
> (but should have), and he didn't test it and so planes fell out of the
> sky.  Ohhh, the humanity of it!"  :-)
>
> I guess I'm feeling frustrated by having to fight so hard against all
> of these fake "problems" for a enhancement has absolutely _no bearing_
> on any of your lives, but tangibly important for my application and
> users.  It's just a simple way for them to express a list of objects
> in a natural way that can be directly interpreted.  Nothing more.
>
> I think you all should let me have this.  If you don't use it, it
> can't affect you.  We haven't run across a regression in the five
> years we've had this in our images, but if we do, I'll certainly fix
> it....
>
>
>
> > 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
> >>
> >>
> >
> >
>

--
Miguel Cobá
http://miguel.leugim.com.mx


Reply | Threaded
Open this post in threaded view
|

Re: terse Object concatenation

Stéphane Rollandin
>  Is some new syntax to write
> arrays. This gives the promise that can be used everywhere without
> adverse effects (like the ones others have highlighted), with uniformity
> in its usage and generally a good practice in smalltalk.

Exactly. This is a very good summary of why I wouldn't like the proposal
to be included in the trunk.


Now about the term "concatenation": the proposal is not about
concatenation at all, it is about collection making.

Concatenation of two objects leads to another object of more or less the
same kind; it does not lead to a collection of the two initial objects.
In Squeak #, is used for concatenation, braces for forming a collection
out of objects.

These are two very different things; the proposal is reifying a
confusion between them, effectively saying that in some unclear way
anObject is anObject and {anObject} at the same time.

Would the proposal be accepted, such a confusion would potentially
propagate everywhere; in my view, this is worse than actually breaking
some code.


Stef



Reply | Threaded
Open this post in threaded view
|

Re: terse Object concatenation

Stéphane Rollandin
Let me illustrate my previous post with what I did in MuO.

MuO is a framework for music composition. Any MusicalElement represent
some sort of musical data in a temporal framework.

Two MusicalElement instances can always be mixed; the resulting mix is
always a MusicalElement.

Here enters the concatenation/collection making ambiguity.

If a is a MusicalNote, and b another MusicalNote, then

        a,b

is a MusicalPhrase.

While if a and b are musicalPhrase, then

        a,b

is also a MusicalPhrase.

This is in the line of Chris' proposal (which I am opposed to); the
reason I find it meaningful here is that both MusicalNote and
MusicalPhrase are subclasses of MusicalElement.

In the context of what a MusicalElement is, it makes sense that
concatenation of two objects leads to an object of a different class,
similar to a collection, because both the initial objects and the
collection are assured to mix freely via the MusicalElement protocol.

In the general case though, there is no reason that the protocol (taken
in the broadest sense, as "expected usage") applying to object also
applies to a collection of objects. Indeed, a collection of object is
generally ignorant of the nature of its elements. String is an exception
and, guess what, String does generalize concatenation to non-String objects.

Similarly, AbstractSound implements #, in a way close to Chris'
proposal, since if a and b are sounds then a,b is a SequentialSound (the
analog of collection in that case). But note that SequentialSound in an
AbstractSound.

So I think we have a pattern here: Chris' proposal make sense to me when
it operates in a delimited domain where it is clear why we can consider
anObject to also represent {anObject}. Such a domain implicitely states
that its objects all have a structural property of potential
multiplicity that makes it logical that the simplest of these objects
can be considered as composed of themselves alone.

So a Character is a sort of singleton String, seen from the point of
view of String. Similarly, an AbstractSound is a singleton
SequentialSound, while a MusicalNote is a singleton MusicalPhrase, as
seen by MusicalElement.

In this way of looking to the problem, Chris's proposal makes the point
of view of Array important enough that any Object can be seen as an
Array singleton.

That's where I disagree, for at least two reasons:
- philosophically, I don't think Array is so central in Smalltalk that
we have to look to every object through its eyes
- practically, we have a rich set of Collections, so why pick up Array
other IdentitySet or SequenceableCollection ?


sorry for the long post, hope it was clear...

Stef





Reply | Threaded
Open this post in threaded view
|

Re: terse Object concatenation

Randal L. Schwartz
In reply to this post by Stéphane Rollandin
>>>>> "Stéphane" == Stéphane Rollandin <[hidden email]> writes:

Stéphane> Concatenation of two objects leads to another object of more
Stéphane> or less the same kind; it does not lead to a collection of the
Stéphane> two initial objects. In Squeak #, is used for concatenation,
Stéphane> braces for forming a collection out of objects.

That says exactly what I had a gut level feel for.  Thanks for
verbalizing it.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Reply | Threaded
Open this post in threaded view
|

Re: terse Object concatenation

Chris Muller-3
In reply to this post by Stéphane Rollandin
Hey, brilliant explanation, thanks.  I respect _this_ argument and,
for the sake of moving on, will retract my proposal (sorry Brent!).
But please consider my final thoughts that address your explanation,
and I will now shut up..  :)

_Semantically_, I think it's reasonable to expect that, for most any
kind of "Object", whether it's a musical-note or a coffee-mug, if you
can have one of them, you can always consider the possibility of two
or more.  Yes, there are singletons, but a 98% case is worth a
generalization in Object.

I do have three such cases across my various applications (in separate
class-hierarchies), so it made sense for me to "factor" this concept
into their common superclass, Object,

Object>>, aCollection
    ^ self asCollection, aCollection asCollection

rather than duplicated three times.

Now, notice how only the _abstract portion_ of our common "pattern"
(as you rightly called it) is in Object.  This implementation provides
the general behavior needed for muO and all three of my apps (as well
as String and SequentialSound, etc.) to express a list of their
primary domain objects.  Instead of muO implementing #, (comma) it
would just implement #asCollection:

  MusicalPhrase>>#asCollection
     ^ self

  MusicalNote>>#asCollection
    ^ MusicalPhrase with: self

I probably should have tried to sell this angle to you earlier, but
Object>>#, is not much code for me to duplicate.  And, while we
obviously agree that comma #, is a beautiful way to express a list,
developers don't need it and the need for direct Smalltalk
interpretation of _user_ input is probably rare..  OK!

(But I need to still consider Object>>#asCollection though, so I don't
have to duplicate THAT in all three places too..)

Good debate, thanks Stef.

 - Chris



2010/9/24 Stéphane Rollandin <[hidden email]>:

> Let me illustrate my previous post with what I did in MuO.
>
> MuO is a framework for music composition. Any MusicalElement represent some
> sort of musical data in a temporal framework.
>
> Two MusicalElement instances can always be mixed; the resulting mix is
> always a MusicalElement.
>
> Here enters the concatenation/collection making ambiguity.
>
> If a is a MusicalNote, and b another MusicalNote, then
>
>        a,b
>
> is a MusicalPhrase.
>
> While if a and b are musicalPhrase, then
>
>        a,b
>
> is also a MusicalPhrase.
>
> This is in the line of Chris' proposal (which I am opposed to); the reason I
> find it meaningful here is that both MusicalNote and MusicalPhrase are
> subclasses of MusicalElement.
>
> In the context of what a MusicalElement is, it makes sense that
> concatenation of two objects leads to an object of a different class,
> similar to a collection, because both the initial objects and the collection
> are assured to mix freely via the MusicalElement protocol.
>
> In the general case though, there is no reason that the protocol (taken in
> the broadest sense, as "expected usage") applying to object also applies to
> a collection of objects. Indeed, a collection of object is generally
> ignorant of the nature of its elements. String is an exception and, guess
> what, String does generalize concatenation to non-String objects.
>
> Similarly, AbstractSound implements #, in a way close to Chris' proposal,
> since if a and b are sounds then a,b is a SequentialSound (the analog of
> collection in that case). But note that SequentialSound in an AbstractSound.
>
> So I think we have a pattern here: Chris' proposal make sense to me when it
> operates in a delimited domain where it is clear why we can consider
> anObject to also represent {anObject}. Such a domain implicitely states that
> its objects all have a structural property of potential multiplicity that
> makes it logical that the simplest of these objects can be considered as
> composed of themselves alone.
>
> So a Character is a sort of singleton String, seen from the point of view of
> String. Similarly, an AbstractSound is a singleton SequentialSound, while a
> MusicalNote is a singleton MusicalPhrase, as seen by MusicalElement.
>
> In this way of looking to the problem, Chris's proposal makes the point of
> view of Array important enough that any Object can be seen as an Array
> singleton.
>
> That's where I disagree, for at least two reasons:
> - philosophically, I don't think Array is so central in Smalltalk that we
> have to look to every object through its eyes
> - practically, we have a rich set of Collections, so why pick up Array other
> IdentitySet or SequenceableCollection ?
>
>
> sorry for the long post, hope it was clear...
>
> Stef
>
>
>
>
>
>

12