[Cuis-dev] unnecessary punctuation

Vanessa Freudenberg vanessa at codefrau.net
Wed Jun 12 14:28:13 PDT 2024


On Wed, Jun 12, 2024 at 6:56 AM Mark Volkmann via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> I saw this example in a YouTube video about Smalltalk this morning:
>
> (2 > 3) ifTrue: ['Yes'] ifFalse: ['No']
>
> It seems to me that none of the parentheses or square brackets are needed
> here.
> The following works the same for me.
>
> 2 > 3 ifTrue: 'Yes' ifFalse: 'No'
>
> Is it true that keyword messages that take no-arg blocks can always take a
> literal value instead?
> It seems this works because the `Object` class defines the `value` method
> to just return `self`.
>

Yes it only works because of Object>>value.

It's also twice as slow to leave out the block brackets because it prevents
compiler optimizations and forces actual sends to be made. You can verify
that by benchmarking, and understand it by looking at the bytecodes
generated and running a message tally.

Nessa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240612/7ef13bfd/attachment.htm>


More information about the Cuis-dev mailing list