Is it OK to leave the [ and ] out for messages like at:ifAbsent: if you don't need a full block?
gemstone, pharo, smalltalk, squeak, visualworks
Solution
The signature:
at: key ifAbsent: aBlock
declares an intention of using a block as a 2nd parameter... But Smalltalk is not a strongly typed language, so, what kind of objects can you pass there? any kind that understand the message #value, so, be careful about each particular meaning of #value in each case, but take advantages of polymorphism!
Problem
In Smalltalk (and specifically Pharo/Squeak) I want to know if it is OK to leave out the "[" and "]" for the argument to messages like at:ifAbsent: if you don't need a block, like this; ``` ^ bookTitles at: bookID ifAbsent: ''. ``` and ``` ^ books at: bookID ifAbsent: nil. ``` the code works because (in Pharo/Squeak) Object>>value just returns self. But I want to know how accepted this use is or if you should always type the [ and ] even when you don't care if the argument is evaluated quickly or more than once.