[squeak-dev] #identityCaseOf:
Levente Uzonyi
leves at caesar.elte.hu
Sun Mar 28 16:08:25 UTC 2021
On Sun, 28 Mar 2021, Tobias Pape wrote:
>
>
>> On 28. Mar 2021, at 16:03, Levente Uzonyi <leves at caesar.elte.hu> wrote:
>>
>> On Sun, 28 Mar 2021, Tobias Pape wrote:
>>
>>> Hi
>>>
>>>
>>>> On 28. Mar 2021, at 07:12, tim Rowledge <tim at rowledge.org> wrote:
>>>>> On 2021-03-27, at 11:47 AM, Thiede, Christoph <Christoph.Thiede at student.hpi.uni-potsdam.de> wrote:
>>>>> Hi all,
>>>>> the proposal is in the title. :-) Do you think we could need something like #identityCaseOf:[otherwise:], analogously to #caseOf:[otherwise:], on Object?
>>>> I would go with 'not'. I'm not a fan of #caseOf: either. Far too like C. Slippery slope to "oooh, let's have thing.ivar.ivar to be like structs."
>>>
>>> Exactly.
>>> If you need something like that, there's either a missing polymorphic abstraction, or a few ifTrue:'s are sufficient.
>>> (as in the case of #update:
>>>
>>> update: aSymbol
>>>
>>> aSymbol == #foo ifTrue: [^ self knorz].
>>> aSymbol == #bar ifTrue: [^ self berfp].
>>> ^ false
>>>
>>> I think this is sufficient.
>>
>> Those ifTrue:'s quickly render your code unreadable or force you to extract chunks of your code into a separate method which can impair legibility.
>>
>>>
>>> Otherwise, use an IdentityDictionary?
>>
>> Ah, the good old Pharo-way of doing things. :D
>
> what?
> -t
I meant the pattern that became popular in Pharo to replace caseOf:. Your
example would be something like
update: aSymbol
^(Dictionary newFrom: {
#foo -> [ self knorz ].
#bar -> [ self berfp ]
})
at: aSymbol
ifPresent: [ :block | block value ]
ifAbsent: [ false ]
There's also another variant[1] which uses an array and #detect:.
Levente
[1] http://forum.world.st/could-we-agree-to-remove-caseOf-and-caseOf-otherwise-td3302475.html
>
>>
>> All-in-all, it looks as though we're slipping into another caseOf: vs no-caseOf: discussion. Let's not do that.
>>
>>
>> Levente
>>
>>>
>>> Best regards
>>> -Tobias
More information about the Squeak-dev
mailing list
|