Looking for a good method name...

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

Looking for a good method name...

Travis Griggs-4
http://objology.blogspot.com/2010/11/in-search-of-method-i-cant-name.html

--
Travis Griggs
Objologist
Light travels faster than sound. This is why some people appear bright  
until you hear them speak...




_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Steffen Märcker
How about mappedTo: ?

Cheers! Steffen



Am 24.11.2010, 06:21 Uhr, schrieb Travis Griggs <[hidden email]>:

> http://objology.blogspot.com/2010/11/in-search-of-method-i-cant-name.html
>
> --
> Travis Griggs
> Objologist
> Light travels faster than sound. This is why some people appear bright
> until you hear them speak...
>
>
>
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Nicolas Cellier
Steffen Märcker <merkste <at> web.de> writes:

>
> How about mappedTo: ?
>
> Cheers! Steffen
>

Hmm...
difficult to find something riming with #collect: #select: #inject: etc...

maybe #associate: ... or if you are Xtreaming, #associating: ;)

Nicolas

(PS, oh the antibot confirmation word in gmane is streams!)





_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

John Samuel
How about #project: ?

John

On 24/11/2010 12:56, "nicolas cellier" <[hidden email]>
wrote:

> Steffen Märcker <merkste <at> web.de> writes:

>
> How about mappedTo: ?
>
>
> Cheers! Steffen
>

Hmm...
difficult to find something riming with #collect:
> #select: #inject: etc...

maybe #associate: ... or if you are Xtreaming,
> #associating: ;)

Nicolas

(PS, oh the antibot confirmation word in gmane is
> streams!)





_______________________________________________
vwnc mailing
> list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc




_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Reinout Heeck-2
In reply to this post by Travis Griggs-4
On 11/24/2010 6:21 AM, Travis Griggs wrote:
http://objology.blogspot.com/2010/11/in-search-of-method-i-cant-name.html

After reading this I get the impression that there is another problem to be fixed first: missing Dictionary instantiation protocol.

Something like
  Dictionary withKeys: strings mappedUsing: [:each | Security.MD5 new hash: 'Hello World'].



Then the collection hierarchy can implement something like #mappedUsing:

#( 'foo' 'bar' 'baz' )
    mappedUsing: [ :string | (Security.MD5 new hash: 'Hello World')].




Of course this suggests variants like:

aSequence mappedTo: anotherSequence

with underlying Dictionary instantiation protocol #withKeys:andValues:
(name suggested by existing instantiation protocol)





my 2c,

Reinout
-------

-- 
*********************************************************************

Dit e-mailbericht is alleen bestemd voor de geadresseerde(n).

Gebruik door anderen is niet toegestaan. Indien u niet degeadresseerde(n) bent wordt u verzocht de verzender hiervan op de hoogte te stellen en het bericht te verwijderen. Door de elektronische verzending kunnen aan de inhoud van dit bericht geen rechten worden ontleend.

Soops B.V. is gevestigd te Amsterdam, Nederland, en is geregistreerd bij de Kamer van Koophandel onder nummer 33240368.
Soops B.V. levert volgens de Fenit voorwaarden, gedeponeerd te Den Haag op 8 december 1994 onder nummer 1994/189.
**********************************************************************

This e-mail message is intended to be exclusively for the addressee.

If you are not the intended recipient you are kindly requested not to make any use whatsoever of the contents and to notify the sender immediately by returning this e-mail message. No rights can be derived from this message.

Soops B.V. is a private limited liability company and has its seat at Amsterdam, The Netherlands and is registered with the Trade Registry of the Chamber of Commerce and Industry under number 33240368.
Soops B.V. delivers according to the General Terms and Conditions of Business of Fenit, registered at The Hague, The Netherlands on December 8th, 1994, under number 1994/189
**********************************************************************


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Alan Knight-2
That's interesting, thinking of it as dictionary protocol. It makes me think of something like

  Dictionary keys: #(1 2 3) values: #(a b c)

as useful protocol in general, and then one could also do something like

   Dictionary keys: #(1 2 3) withValuesFrom: aBlock
or perhaps
   Dictionary keys: #(1 2 3) mappedTo: aBlock

and then something like asDictionary: or mappedUsing: or whatever one might call the instance side method would just be a trivial use of that.


On 2010-11-26 4:42 AM, Reinout Heeck wrote:
On 11/24/2010 6:21 AM, Travis Griggs wrote:
http://objology.blogspot.com/2010/11/in-search-of-method-i-cant-name.html

After reading this I get the impression that there is another problem to be fixed first: missing Dictionary instantiation protocol.

Something like
  Dictionary withKeys: strings mappedUsing: [:each | Security.MD5 new hash: 'Hello World'].



Then the collection hierarchy can implement something like #mappedUsing:

#( 'foo' 'bar' 'baz' )
    mappedUsing: [ :string | (Security.MD5 new hash: 'Hello World')].




Of course this suggests variants like:

aSequence mappedTo: anotherSequence

with underlying Dictionary instantiation protocol #withKeys:andValues:
(name suggested by existing instantiation protocol)





my 2c,

Reinout
-------

-- 
*********************************************************************

Dit e-mailbericht is alleen bestemd voor de geadresseerde(n).

Gebruik door anderen is niet toegestaan. Indien u niet degeadresseerde(n) bent wordt u verzocht de verzender hiervan op de hoogte te stellen en het bericht te verwijderen. Door de elektronische verzending kunnen aan de inhoud van dit bericht geen rechten worden ontleend.

Soops B.V. is gevestigd te Amsterdam, Nederland, en is geregistreerd bij de Kamer van Koophandel onder nummer 33240368.
Soops B.V. levert volgens de Fenit voorwaarden, gedeponeerd te Den Haag op 8 december 1994 onder nummer 1994/189.
**********************************************************************

This e-mail message is intended to be exclusively for the addressee.

If you are not the intended recipient you are kindly requested not to make any use whatsoever of the contents and to notify the sender immediately by returning this e-mail message. No rights can be derived from this message.

Soops B.V. is a private limited liability company and has its seat at Amsterdam, The Netherlands and is registered with the Trade Registry of the Chamber of Commerce and Industry under number 33240368.
Soops B.V. delivers according to the General Terms and Conditions of Business of Fenit, registered at The Hague, The Netherlands on December 8th, 1994, under number 1994/189
**********************************************************************

_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

-- 
Alan Knight [|], Engineering Manager, Cincom Smalltalk
[hidden email]
[hidden email]
http://www.cincom.com/smalltalk

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Steve Cline
It seems the behavior Travis wants is "From a Collection, create a mapping where the key is the original object and the value is transformed from the key". Most replies seem to assume that the original input is a Set or able to become one without loss, though if not you could make it work producing an Array of Associations.  I like the previously mentioned "project:" method name.  Thus:

'abcabc' project: [ :e | e isVowel ]

which would produce an Array (preserving order and duplicates) of Associations.

You could write one implementation on Collection with the above behavior, and a refinement on Set to produce a Dictionary:

'abcabc' asSet project: [ :e | e isVowel ]

What do you think?
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Andres Valloud-4
Hmmm, if you go through a Set first, then it's more expensive
(essentially because the keys will be hashed twice).  On the other hand,
you won't need to implement project: and identityProject:...

It seems a bit complicated.  What's the problem with (following Travis'
code)

answer := Dictionary new. "You specify which kind you want"
setOfStrings do:
   [:each |
     answer
       at: each
       put: (Security.MD5 new hash: each) "I assume each instead of a
constant"
   ].
^answer

Maybe we could use the Rewrite Tool and see how frequent this code
pattern is.  Perhaps with more examples the name will be easier to find.

Andres.

On 11/26/10 12:17 , Steve Cline wrote:

>
> It seems the behavior Travis wants is "From a Collection, create a mapping
> where the key is the original object and the value is transformed from the
> key". Most replies seem to assume that the original input is a Set or able
> to become one without loss, though if not you could make it work producing
> an Array of Associations.  I like the previously mentioned "project:" method
> name.  Thus:
>
> 'abcabc' project: [ :e | e isVowel ]
>
> which would produce an Array (preserving order and duplicates) of
> Associations.
>
> You could write one implementation on Collection with the above behavior,
> and a refinement on Set to produce a Dictionary:
>
> 'abcabc' asSet project: [ :e | e isVowel ]
>
> What do you think?
>
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Nicolas Cellier
In reply to this post by Steve Cline
Steve Cline <cline <at> acm.org> writes:

>
> It seems the behavior Travis wants is "From a Collection, create a mapping
> where the key is the original object and the value is transformed from the
> key". Most replies seem to assume that the original input is a Set or able
> to become one without loss, though if not you could make it work producing
> an Array of Associations.  I like the previously mentioned "project:" method
> name.  Thus:
>
> 'abcabc' project: [ :e | e isVowel ]
>
> which would produce an Array (preserving order and duplicates) of
> Associations.
>
> You could write one implementation on Collection with the above behavior,
> and a refinement on Set to produce a Dictionary:
>
> 'abcabc' asSet project: [ :e | e isVowel ]
>
> What do you think?
>

If we must really stick to the ...ect: I have these ones:

#connect:
"connects a value to each element of the receiver"

#recollect:
"a form of collect: with recollection of the elements of the receiver as keys"

Nicolas


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Nicolas Cellier
nicolas cellier <nicolas.cellier.aka.nice <at> gmail.com> writes:

>
> If we must really stick to the ...ect: I have these ones:
>
> #connect:
> "connects a value to each element of the receiver"
>
> #recollect:
> "a form of collect: with recollection of the elements of the receiver as keys"
>
> Nicolas
>


And I just missed #conject: To throw together...

Nicolas

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Steve Cline
In reply to this post by Andres Valloud-4
But from Travis' original post (http://objology.blogspot.com/2010/11/in-search-of-method-i-cant-name.html), I was unsure whether the input collection could be assumed to be unique values in all cases (though his example was).  Looking at your code below assuming that it is the body of a one-keyword message that takes a transformational block as an argument, the variable setofStrings is really 'self',e.g.:

Collection>>#foo: aOneArgBlock
answer := Dictionary new.
self do:
   [:each |
     answer
       at: each
       put: (aOneArgBlock value: each)
   ].
^answer


Invoked as:

originalCollection foo: [ :e | e transformed]

could correctly produce a Dictionary iff
   A. orginalCollection contains unique values
     or
   B. loss of duplicates is acceptable

To have it return something other than a Dictionary, from your comment below ("You specify which kind you want" ) seems to imply either an additional argument (answerType? feels awkward) or multiple methods (fooAsDictionary: vs. fooAsArray:).  Just trying to comply with the original request for a simple one keyword method name.

It seems that at some point you have to assume or force unique items in the receiving collection, or allow an implementation that does not require uniqueness.  However, upon taking another look at Travis' first post, it does seem to have the assumption that unique input values are assumed, making a Dictionary a good answer.

Thanks, Steve


On Fri, Nov 26, 2010 at 2:57 PM, Andres Valloud-4 [via Smalltalk] <[hidden email]> wrote:
Hmmm, if you go through a Set first, then it's more expensive
(essentially because the keys will be hashed twice).  On the other hand,
you won't need to implement project: and identityProject:...

It seems a bit complicated.  What's the problem with (following Travis'
code)

answer := Dictionary new. "You specify which kind you want"
setOfStrings do:
   [:each |
     answer
       at: each
       put: (Security.MD5 new hash: each) "I assume each instead of a
constant"
   ].
^answer

Maybe we could use the Rewrite Tool and see how frequent this code
pattern is.  Perhaps with more examples the name will be easier to find.

Andres.

On 11/26/10 12:17 , Steve Cline wrote:

>
> It seems the behavior Travis wants is "From a Collection, create a mapping
> where the key is the original object and the value is transformed from the
> key". Most replies seem to assume that the original input is a Set or able
> to become one without loss, though if not you could make it work producing
> an Array of Associations.  I like the previously mentioned "project:" method
> name.  Thus:
>
> 'abcabc' project: [ :e | e isVowel ]
>
> which would produce an Array (preserving order and duplicates) of
> Associations.
>
> You could write one implementation on Collection with the above behavior,
> and a refinement on Set to produce a Dictionary:
>
> 'abcabc' asSet project: [ :e | e isVowel ]
>
> What do you think?
>
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc



View message @ http://forum.world.st/Looking-for-a-good-method-name-tp3056676p3060907.html
To unsubscribe from Looking for a good method name..., click here.



--
Steve Cline  [hidden email] http://www.clines.org http://www.linkedin.com/in/stevecline
"Do what's right, and try to get along with people, in that order"
- Ezra Taft Benson
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Andres Valloud-4
Yes... the devil is always in the details!

On 11/26/10 14:05 , Steve Cline wrote:

> But from Travis' original post
> (http://objology.blogspot.com/2010/11/in-search-of-method-i-cant-name.html),
> I was unsure whether the input collection could be assumed to be unique
> values in all cases (though his example was).  Looking at your code
> below assuming that it is the body of a one-keyword message that takes a
> transformational block as an argument, the variable setofStrings is
> really 'self',e.g.:
>
> Collection>>#foo: aOneArgBlock
> answer := Dictionary new.
> self do:
>     [:each |
>       answer
>         at: each
>         put: (aOneArgBlock value: each)
>     ].
> ^answer
>
>
> Invoked as:
>
> originalCollection foo: [ :e | e transformed]
>
> could correctly produce a Dictionary iff
>     A. orginalCollection contains unique values
>       or
>     B. loss of duplicates is acceptable
>
> To have it return something other than a Dictionary, from your comment
> below ("You specify which kind you want" ) seems to imply either an
> additional argument (answerType? feels awkward) or multiple methods
> (fooAsDictionary: vs. fooAsArray:).  Just trying to comply with the
> original request for a simple one keyword method name.
>
> It seems that at some point you have to assume or force unique items in
> the receiving collection, or allow an implementation that does not
> require uniqueness.  However, upon taking another look at Travis' first
> post, it does seem to have the assumption that unique input values are
> assumed, making a Dictionary a good answer.
>
> Thanks, Steve
>
>
> On Fri, Nov 26, 2010 at 2:57 PM, Andres Valloud-4 [via Smalltalk]
> <[hidden email] </user/SendEmail.jtp?type=node&node=3061011&i=0>> wrote:
>
>     Hmmm, if you go through a Set first, then it's more expensive
>     (essentially because the keys will be hashed twice).  On the other
>     hand,
>     you won't need to implement project: and identityProject:...
>
>     It seems a bit complicated.  What's the problem with (following Travis'
>     code)
>
>     answer := Dictionary new. "You specify which kind you want"
>     setOfStrings do:
>         [:each |
>           answer
>             at: each
>             put: (Security.MD5 new hash: each) "I assume each instead of a
>     constant"
>         ].
>     ^answer
>
>     Maybe we could use the Rewrite Tool and see how frequent this code
>     pattern is.  Perhaps with more examples the name will be easier to
>     find.
>
>     Andres.
>
>     On 11/26/10 12:17 , Steve Cline wrote:
>
>      >
>      > It seems the behavior Travis wants is "From a Collection, create
>     a mapping
>      > where the key is the original object and the value is transformed
>     from the
>      > key". Most replies seem to assume that the original input is a
>     Set or able
>      > to become one without loss, though if not you could make it work
>     producing
>      > an Array of Associations.  I like the previously mentioned
>     "project:" method
>      > name.  Thus:
>      >
>      > 'abcabc' project: [ :e | e isVowel ]
>      >
>      > which would produce an Array (preserving order and duplicates) of
>      > Associations.
>      >
>      > You could write one implementation on Collection with the above
>     behavior,
>      > and a refinement on Set to produce a Dictionary:
>      >
>      > 'abcabc' asSet project: [ :e | e isVowel ]
>      >
>      > What do you think?
>      >
>     _______________________________________________
>     vwnc mailing list
>     [hidden email] <http://user/SendEmail.jtp?type=node&node=3060907&i=0>
>     http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
>
>     ------------------------------------------------------------------------
>     View message @
>     http://forum.world.st/Looking-for-a-good-method-name-tp3056676p3060907.html
>     <http://forum.world.st/Looking-for-a-good-method-name-tp3056676p3060907.html?by-user=t>
>     To unsubscribe from Looking for a good method name..., click here
>     <
>
>
>
>
>
> --
> Steve Cline [hidden email]
> </user/SendEmail.jtp?type=node&node=3061011&i=1>
http://www.clines.org
> <http://www.clines.org?by-user=t> http://www.linkedin.com/in/stevecline
> "Do what's right, and try to get along with people, in that order"
> - Ezra Taft Benson
>
> ------------------------------------------------------------------------
> View this message in context: Re: Looking for a good method name...
> <http://forum.world.st/Looking-for-a-good-method-name-tp3056676p3061011.html>
> Sent from the VisualWorks mailing list archive
> <http://forum.world.st/VisualWorks-f1402296.html> at Nabble.com.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Steve Cline
I think I like connect: better than project: for what it does, because we are connecting an original value to a derivative value
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

Steve Cline
Just came up with a one method implementation:

connect: aOneArgBlock
^self
    inject: Dictionary new
    into: [ :accumulator :e  | accumulator at: e put: (oneArgBlock value: e); yourself]

ttfn, Steve
jas
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a good method name...

jas
In reply to this post by Travis Griggs-4
Perplect not withstanding,
#reCollect: gets my vote, with one caveat.

Given

  projection1 := [:key| MD5 hash: key].
  projection2 := [:key| MD5 hash: 'Hello World'].
  map1 := setOfStrings reCollect: projection1.
  map2 := setOfStrings reCollect: projection2.

map1 and map2 will have same keys, different values.

Given

  map3 := map1 reCollect: projection1.

map1 and map3 *should* have same keys and values.


-Jim



09:21 PM 11/23/2010, Travis Griggs wrote:

>http://objology.blogspot.com/2010/11/in-search-of-method-i-cant-name.html
>
>--
>Travis Griggs
>Objologist
>Light travels faster than sound. This is why some people appear bright  
>until you hear them speak...
>
>
>
>
>_______________________________________________
>vwnc mailing list
>[hidden email]
>http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
>
>__________ Information from ESET NOD32 Antivirus, version of virus signature database 5634 (20101119) __________
>
>The message was checked by ESET NOD32 Antivirus.
>
>http://www.eset.com


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc