<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p></p>
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:12pt">
<p>Hi all,</p>
<p><br>
</p>
<p>thanks for all the opinions! :-) </p>
<div id="x_Signature">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">
<div class="x__rp_U4 x_ms-font-weight-regular x_ms-font-color-neutralDark x_rpHighlightAllClass x_rpHighlightBodyClass" id="x_Item.MessageUniqueBody" style="font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont">
<div dir="ltr">
<div id="x_divtagdefaultwrapper"><font face="Calibri,Helvetica,sans-serif,EmojiFont,Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols">
<div id="x_Signature">
<div style="margin:0px"><font style="font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont"><font size="3" color="black"><span style="font-size:12pt"><a href="http://www.hpi.de/" target="_blank" rel="noopener noreferrer" id="LPNoLP"><font size="2"><font color="#757B80"></font></font></a></span></font></font></div>
</div>
</font></div>
</div>
</div>
</div>
<div class="x__rp_T4" id="x_Item.MessagePartBody"><br>
</div>
<div class="x__rp_T4" id="x_Item.MessagePartBody">I see that the general use of #caseOf:[otherwise:] is probably of matter of taste - personally, I like it to remove duplication. Kent Beck even recommends refactoring something like this:</div>
</div>
</div>
</div>
</div>
<blockquote style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px; margin:0px 0px 0px 40px; border:none; padding:0px">
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody"><span style="font-size:12pt">aBoolean ifTrue: [^1] ifFalse: [^2]</span></div>
</div>
</div>
</div>
</blockquote>
<div dir="ltr" style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">to something like that:</div>
</div>
</div>
</div>
<blockquote style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px; margin:0px 0px 0px 40px; border:none; padding:0px">
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">^ aBoolean ifTrue: [1] ifFalse: [2]</div>
</div>
</div>
</div>
</blockquote>
<div dir="ltr" style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">So I have the feeling that he would also recommend refactoring</div>
</div>
</div>
</div>
<blockquote style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px; margin:0px 0px 0px 40px; border:none; padding:0px">
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">anInteger = 1 ifTrue: [^ #one].</div>
</div>
</div>
</div>
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">anInteger = 2 ifTrue: [^ #two].</div>
</div>
</div>
</div>
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">anInteger = 3 ifTrue: [^ #three].</div>
</div>
</div>
</div>
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">^ self error</div>
</div>
</div>
</div>
</blockquote>
<div dir="ltr" style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">to:</div>
</div>
</div>
</div>
<blockquote style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px; margin:0px 0px 0px 40px; border:none; padding:0px">
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">anInteger caseOf: {</div>
</div>
</div>
</div>
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">    [1] -> [#one].</div>
</div>
</div>
</div>
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">    [2] -> [#two].</div>
</div>
</div>
</div>
<div dir="ltr" style="font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div class="x__rp_T4" id="x_Item.MessagePartBody">    [3] -> [#three] }</div>
</div>
</div>
</div>
</blockquote>
<div dir="ltr" style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:12pt">
<div dir="ltr" style="font-size:12pt">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; margin:0px">
<div>
<div class="x__rp_T4" id="x_Item.MessagePartBody">However, I don't know him personally, so this is an assumption only, of course. ;-)</div>
</div>
<div><br>
@David: I find your thoughts about boring code interesting. My personal perspective is rather different, I always try to minimize duplication, but I have already been having many discussions about this with some fellow students, so probably, the best solution
 lies somewhere in the middle between boringness (Robert Martin) and deduplication (Kent Beck) ... :-)</div>
<div><br>
</div>
<div>> <span style="font-size:12pt">If you were to add #identityCaseOf:[otherwise:] to the protocol of </span><span style="font-size:12pt">Object, there is a risk that people would perceive it as a feature </span><span style="font-size:12pt">of the language,
 and as something that they should try to incorporate </span><span style="font-size:12pt">into their own code. That would not be a good thing.</span>
<div><br>
</div>
<div>Why not (except the reasons you listed above), if I may ask? :-) #caseOf:[otherwise:] already *is* part of the protocol of Object, and so are #yourself and #in:, too. IMHO they are kind of features of the language - not a syntactical way, thanks to Smalltalk
 minimalism, but still, they are understood by every object. Unless we deprecate them, we should indeed assume that people use them, of course.</div>
<div><br>
</div>
<div>@Tim:</div>
<div><br>
</div>
<div>> <span>Far too like C.</span></div>
<div><span><br>
</span></div>
<div><span>Again, why please? :-) I'm not a big fan of C either, but IMO switch/select/case is not the worst concept when it allows you to eliminate some duplication. Still, I would not say #caseOf:[otherwise:] is the end goal in every case - often it helps
 you to identify data in your code, and a further refactoring step could be to extract the data into a separate method as a dictionary. See [1] for further thoughts about this.</span></div>
<div><span><br>
</span></div>
<div><span>@Levente: Glad you like it! Regarding arguments, did you read [2]? It's already a bit older but I have not continued working on this since I'm afraid have not got any feedback on the proposal. :-)</span></div>
<div><span><br>
</span></div>
<div><span>[1] <a href="https://twitter.com/LinqLover/status/1375191096658178050" class="x_OWAAutoLink" id="LPlnk481365">https://twitter.com/LinqLover/status/1375191096658178050</a></span></div>
<div>[2] <a href="http://forum.world.st/Merge-Request-caseOf-otherwise-with-arguments-td5112223.html" class="x_OWAAutoLink" id="LPlnk937470">http://forum.world.st/Merge-Request-caseOf-otherwise-with-arguments-td5112223.html</a></div>
<br>
</div>
<div>Best,</div>
<div>Christoph</div>
</div>
</div>
</div>
<div id="x_Signature">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div name="x_divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Levente Uzonyi <leves@caesar.elte.hu><br>
<b>Gesendet:</b> Sonntag, 28. März 2021 10:33:32<br>
<b>An:</b> The general-purpose Squeak developers list<br>
<b>Betreff:</b> Re: [squeak-dev] #identityCaseOf:</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Hi Christoph,<br>
<br>
I see some value having #identityCaseOf:, so +1 from me.<br>
<br>
But what would be a more interesting thing to explore (yes, I'm derailing <br>
this conversation now because the answer to your question is yes already <br>
:)) is to extend the functionality of #caseOf:.<br>
<br>
For example, passing the object to the condition block (or even the result <br>
block) could be useful:<br>
<br>
self someComplexExpression caseOf: {<br>
         [ 1 ] -> [ self success ]<br>
         [ :value | value odd ] -> [ :value | self processEvenValue: value - 1 ].<br>
         [ :value | true "it's even ] -> [ :value | self processEvenValue ] }<br>
<br>
There are two new things in the example:<br>
- the value of self someComplexExpression is optionally passed to the <br>
blocks. Yes, that could be done by creating a temporary variable. The <br>
compiler could do exactly that behind the scenes.<br>
- when the value is passed to the matcher block, possibilities are greatly <br>
extended. For example, it could even reproduce #identityCaseOf:<br>
<br>
         foo caseOf: {<br>
                 [ :o | o == #foo ] -> [ self foo ].<br>
                 [ :o | o == #bar ] -> [ self bar ] }<br>
<br>
The same thing could be done with the otherwise block too:<br>
<br>
         self foo<br>
                 caseOf: { ... }<br>
                 otherwise: [ :value | value ]<br>
<br>
<br>
Levente<br>
<br>
<br>
On Sat, 27 Mar 2021, Thiede, Christoph wrote:<br>
<br>
> <br>
> Hi all,<br>
> <br>
> <br>
> the proposal is in the title. :-) Do you think we could need something like #identityCaseOf:[otherwise:], analogously to #caseOf:[otherwise:], on Object?<br>
> <br>
> <br>
> Here is my motivation: I very often use #caseOf:[otherwise:] to eliminate nested if blocks (for one of many examples, take a look at PreferenceBrowserMorph >> #keyPressed:). In one recent situation [1], however, I confused<br>
> equality and identity (I have to admit that this is a common error of mines) so I had to convert my beautiful #caseOf: statement back to a boring list of if checks. I wonder whether we could - or should - introduce something<br>
> like #identityCaseOf:otherwise: (names subjected to discussion) for such situations?<br>
> <br>
> <br>
> Historically, I guess this has not been built because #caseOf: has probably been inspired by the switch/select/case statement of other languages, which usually only accept constant case values. But in Smalltalk, luckily, we<br>
> do not have this restriction, thus I'm wondering whether there is any reason to have #caseOf: but not #identityCaseOf:. Looking forward to your opinions! :-)<br>
> <br>
> <br>
> Best,<br>
> <br>
> Christoph<br>
> <br>
> <br>
> [1] https://github.com/LinqLover/SimulationStudio/commit/ddf0ef3e21c63a2fd9b08703c8e9ff213b7b6b0b<br>
> <br>
></div>
</span></font>
</body>
</html>