[Pharo-dev] what is the new way to do Smalltalk at: #MyClass?

Camillo Bruni camillobruni at gmail.com
Mon Aug 26 06:12:19 EDT 2013

On 2013-08-26, at 11:46, Norbert Hartl <norbert at hartl.name> wrote:

> Am 26.08.2013 um 10:56 schrieb Esteban Lorenzano <estebanlm at gmail.com>:
>> On Aug 25, 2013, at 9:40 AM, Camille Teruel <camille.teruel at gmail.com> wrote:
>>> On 24 août 2013, at 19:20, Camillo Bruni wrote:
>>>> We have now:
>>>> String >> #asClass
>>>> String >> #asClassIfAbsent:
>>>> String >> #asClassIfPresent:
>>> I don't understand why we need this new way.
>>> Is it just to avoid calling 'Smalltalk globals at: #MyClass'?
>> exactly
>>> Because these names are confusing, and the 'as' prefix suggests a conversion while it's an access (with indirection but still a mere access).
>>> And #asClass has no sender.
>>> If you think 'Smalltalk globals at: #MyClass' is really too long to type, lets just create a new global ThisEnvironment := Smalltalk globals.
>> this was already discussed. With #asClass and relatives what you have is a better abstraction jut because you are decoupled of "Smalltalk globals", it is not a big win now, but it open doors to better designs with environments, etc. 
>> At least, that was my understanding when the issue arise at the beginning.
> I just find it strange that an as* selector might _not_ return anything needing a #asClassIfAbsent: selector. While I'm understanding the intention it does not fit in my had. To me it worsens the understanding of as* conversion selectors. 

It works the same way as the dictionary protocol with #at:
`#adsfasdf asClass` will signal an error, hence for compatibility you have the *IfAbsent: protocols. Otherwise you simply cannot replace all the users of `Smalltalk at:` and `Smalltalk globals at:` which is the long term goal.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 447 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20130826/bcc528a9/attachment.asc>

More information about the Pharo-dev mailing list