<html><head><style id="css_styles" type="text/css"><!--blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc }
blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding-top: 0px; }
a img { border: 0px; }
table { border-collapse: collapse; }
li[style='text-align: center;'], li[style='text-align: center; '], li[style='text-align: right;'], li[style='text-align: right; '] {  list-style-position: inside;}
body { font-family: 'Segoe UI'; font-size: 12pt; }
.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb solid; padding-left: 0.3em; }
--></style></head><body><div><br /></div>
<div style="clear:both"><br /></div>
<div><br /></div>
<div>
<div>On 12-Jun-24 11:32:59 PM, "Mark Volkmann via Cuis-dev" <<a href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.cuis.st</a>> wrote:</div></div><div><br /></div>
<div id="xa01bc30d0c3a40f"><blockquote cite="CAFfRWnVgWck8MS+u5Q0EMsgiGt9LuM_c4uR-ZpAeyzcPi3hJDQ@mail.gmail.com" type="cite" class="cite2">
<div dir="ltr"><div dir="ltr">On Wed, Jun 12, 2024 at 4:28 PM Vanessa Freudenberg <<a href="mailto:vanessa@codefrau.net">vanessa@codefrau.net</a>> wrote:<br /></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Wed, Jun 12, 2024 at 6:56 AM Mark Volkmann via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.cuis.st</a>> wrote:<br /></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">I saw this example in a YouTube video about Smalltalk this morning:<div><br /></div><div><font face="monospace">(2 > 3) ifTrue: ['Yes'] ifFalse: ['No']</font></div><div><br /></div><div>It seems to me that none of the parentheses or square brackets are needed here.</div><div>The following works the same for me.</div><div><br /></div><div><font face="monospace">2 > 3 ifTrue: 'Yes' ifFalse: 'No'</font></div><div><br /></div><div>Is it true that keyword messages that take no-arg blocks can always take a literal value instead?</div><div>It seems this works because the `Object` class defines the `value` method to just return `self`.</div></div></blockquote><div><br /></div><div>Yes it only works because of Object>>value.</div></div></div></blockquote><div><br /></div><div>I assumed that was intentional to support using objects that are not blocks in cases like this.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>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.</div></div></div></blockquote><div><br /></div><div>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? </div></div><div><br /></div></div></blockquote>>> <span>It's also twice as slow to leave out the block bracket [...]</span><br /><br />Interesting - I've never realized the difference :) So if I understand correctly the #ifTrue:ifFalse message gets inlined only when used with block arguments, and it gets really sent when used without blocks; which means not only there's one more send but also that **both** 'Yes' and 'No' expressions get evaluated before sending <span>#ifTrue:ifFalse (hence twice as slow?). Inlining allows the runtime to evaluate only the "right" alternative. Here's the bytecode:</span></div><div id="xa01bc30d0c3a40f"><span><br /></span></div><div id="xa01bc30d0c3a40f"><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;">2 > 3 ifTrue: 'Yes' ifFalse: 'No'</span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;"><br /></span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;">49 pushConstant: 2
</span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;">51 pushConstant: 3
</span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;">53 send: >
</span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;">54 pushConstant: 'Yes'
</span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;">55 pushConstant: 'No'
</span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;">56 send: ifTrue:ifFalse:
</span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;">57 returnTop</span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;"><br /></span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;"><br /></span></div><div id="xef07802efd964805b08feaaa9babd533"><span style="font-family: monospace; margin: 0px;"><div id="x64b3333d4b2c46ce95c0017d1b839c0f">(2 > 3) ifTrue: ['Yes'] ifFalse: ['No']</div><div id="x64b3333d4b2c46ce95c0017d1b839c0f"><span><br /></span></div><div id="x64b3333d4b2c46ce95c0017d1b839c0f"><span>49 pushConstant: 2
</span></div><div id="x64b3333d4b2c46ce95c0017d1b839c0f"><span>51 pushConstant: 3
</span></div><div id="x64b3333d4b2c46ce95c0017d1b839c0f"><span>53 send: >
</span></div><div id="x64b3333d4b2c46ce95c0017d1b839c0f"><span>54 jumpFalse: 57
</span></div><div id="x64b3333d4b2c46ce95c0017d1b839c0f"><span>55 pushConstant: 'Yes'
</span></div><div id="x64b3333d4b2c46ce95c0017d1b839c0f"><span>56 jumpTo: 58
</span></div><div id="x64b3333d4b2c46ce95c0017d1b839c0f"><span>57 pushConstant: 'No'
</span></div><div id="x64b3333d4b2c46ce95c0017d1b839c0f"><span>58 returnTop</span></div></span></div></div><div id="xa01bc30d0c3a40f"><span><br /></span></div><div id="xa01bc30d0c3a40f"><span>Thanks</span>,</div><div id="xa01bc30d0c3a40f">Jaromir</div><div id="xa01bc30d0c3a40f"><span><br /></span></div><div id="xa01bc30d0c3a40f"><span><br /></span></div><div id="xa01bc30d0c3a40f"><span><br /></span></div><div id="xa01bc30d0c3a40f"><span><br /></span></div><div id="xa01bc30d0c3a40f"><span><br /></span></div><div id="xa01bc30d0c3a40f"><span><br /></span></div><div id="xa01bc30d0c3a40f"><span> </span><blockquote cite="CAFfRWnVgWck8MS+u5Q0EMsgiGt9LuM_c4uR-ZpAeyzcPi3hJDQ@mail.gmail.com" type="cite" class="cite2"><div dir="ltr"><div><br /></div></div></blockquote></div>
</body></html>