[Cuis-dev] unnecessary punctuation
Mark Volkmann
r.mark.volkmann at gmail.com
Wed Jun 12 14:32:59 PDT 2024
On Wed, Jun 12, 2024 at 4:28 PM Vanessa Freudenberg <vanessa at codefrau.net>
wrote:
> 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.
>
I assumed that was intentional to support using objects that are not blocks
in cases like this.
> 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.
>
I believe you, but I'm curious why it's faster to send the `value:` message
to a block than to some other kind of object. Are you saying that the
optimizations make it so the `value:` message is not actually sent to a
block in this case and code in the block gets inlined?
--
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240612/c46f3726/attachment.htm>
More information about the Cuis-dev
mailing list