[squeak-dev] Dictionary >> #at:ifAbsentPut:ifPresentPut:

Tobias Pape Das.Linux at gmx.de
Sat May 1 06:54:21 UTC 2021

> On 1. May 2021, at 01:26, stlutz <dev at stlutz.net> wrote:
> Christoph Thiede wrote
> What do you think, should we copy this into the Trunk?
> Personally, I'd get good use out of at:ifPresentPut: and at:ifPresentPut:ifAbsentPut:.
> I seriously considered adding them as extensions in a couple of projects.
> Christoph Thiede wrote
> Also, I'm not sure about the order of arguments.
> The pattern other selectors in Squeak follow is present first, absent second.
> We should probably keep to that pattern.
> Tobias Pape wrote
> I find it a bit too specific for trunk.
> It's quite an edge case...
> FWIW I encountered this case quite a few times over the years.
> It's essentially always a concern when storing and updating value objects in dictionaries.

Temporary variables are not your enemy.

Or even:

 (foo hasKey: 'abc')
   ifTrue: [foo at: 'abc' put: 'def']

Updating existing values really does not need shortcuts.

Initial defaults are another thing, but I think ifPresentPut: is a malpattern…

Best regards

> Levente Uzonyi wrote
> If wanted to have a special method for that case, I would try to look up the key only once.
> +1
> Stephan 
> Sent from the Squeak - Dev mailing list archive at Nabble.com.

More information about the Squeak-dev mailing list