<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><div style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">On Apr 22, 2014, at 8:01, "Lucas Malor" <<a href="mailto:7vsfeu4pxg@snkmail.com">7vsfeu4pxg@snkmail.com</a>> wrote:</div><div style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); "><br></div><blockquote type="cite" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); "><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 20 April 2014 04:17, Bruce Leban <a href="http://bruce-at-leapyear.org" target="_blank">bruce-at-leapyear.org</a> |<a href="http://python-ideas-at-python.org" target="_blank">python-ideas-at-python.org</a>| <span dir="ltr"><<a href="mailto:vajg1g2cqt@sneakemail.com" target="_blank">vajg1g2cqt@sneakemail.com</a>></span> wrote:<br><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_extra"><br>I found that the ugliest part of your proposal since it hides the first case and at the same time makes it appear special when it isn't.</div></div></blockquote><div><br></div><div>Myabe yes, but if you "translate" it in an if-elif, also the if seems to be "special".<br></div></div></div></div></blockquote><div style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); "><br></div><div style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">Yes, there is a difference, but it's not nearly as dramatic as with your version. The conditions still look roughly parallel, only one short word away from the indent point, instead of the first one being way off to the right.</div></div><div style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); "><br></div><div>On Apr 22, 2014, at 8:27, "Lucas Malor" <<a href="mailto:7vsfeu4pxg@snkmail.com">7vsfeu4pxg@snkmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div><div>Sorry, I didn't read it carefully. Anyway, youe example can be written as:<br><br><div class="gmail_extra"><blockquote style="font-size:13px;margin:0px 0px 0px 40px;font-family:arial,sans-serif;padding:0px;border:medium none">
<div><div><font face="courier new, monospace">for i in range(5):</font></div>
<div><font face="courier new, monospace"> print(i, end=' => ')</font></div></div><div><div><font face="courier new, monospace"> if i == 1:</font></div>
<div><div><font face="courier new, monospace"> print('one')</font></div><div><span style="font-family:'courier new',monospace"> elif i == (2,3):</span></div></div></div></blockquote><div>
<blockquote style="font-size:13px;margin:0px 0px 0px 40px;font-family:arial,sans-serif;padding:0px;border:medium none">
<span style="font-family:'courier new',monospace"> print('tuple(two, three)')</span></blockquote><blockquote style="font-size:13px;margin:0px 0px 0px 40px;font-family:arial,sans-serif;padding:0px;border:medium none">
<div><div><font face="courier new, monospace"> elif i in (2, 3):</font></div></div><div><font face="courier new, monospace"> print('two or three')</font></div>
<div><font face="courier new, monospace"> elif i > 3:</font></div><div><font face="courier new, monospace"> print('more than three')</font></div></blockquote><blockquote style="font-size:13px;margin:0px 0px 0px 40px;font-family:arial,sans-serif;padding:0px;border:medium none">
<span style="font-family:'courier new',monospace"> else:</span><br></blockquote><blockquote style="font-size:13px;margin:0px 0px 0px 40px;font-family:arial,sans-serif;padding:0px;border:medium none"><font face="courier new, monospace"> print('unmatched')</font></blockquote>
</div></div><br></div>and it's much simpler to read. </div></div></div></blockquote><div><br></div><div>That's pretty much his point. The same can be said for all of your examples.</div><div><br></div><div>Your version is only "simpler" in that your "case" and "elcase" are spelled "if case" and "elif case" in his. Meanwhile, your version is more complex in that the first case is crammed on the same line with the "switch". Also, instead of automatically handling tuples in a natural and obvious way, you're forced to invent a new builtin class and a new display form just to distinguish tuples inline in a case label, and still can't easily handle the distinction in a natural and readable way. And, while his can be trivially extended to handle other types of comparison besides == and in, yours can't. So, you've come up with something that's more complex, less natural, and less powerful than what we can already do, and the only benefit is a little bit of brevity.</div><br><blockquote type="cite"><div><div dir="ltr"><div>I suggested the switch statement for a simpler alternative to the if-elif chain.</div><div><div><div><br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On 22 April 2014 17:15, Chris Angelico <a href="http://rosuav-at-gmail.com">rosuav-at-gmail.com</a> |<a href="http://python-ideas-at-python.org">python-ideas-at-python.org</a>| <span dir="ltr"><<a href="mailto:iv1yq22odt@sneakemail.com" target="_blank">iv1yq22odt@sneakemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Wed, Apr 23, 2014 at 1:01 AM, Lucas Malor <<a href="mailto:7vsfeu4pxg@snkmail.com">7vsfeu4pxg@snkmail.com</a>> wrote:<br>
>> for i in range(5):<br>
>> print(i, end=' => ')<br>
>> case = Case(i)<br>
>> if case(1):<br>
>> print('one')<br>
>> elif case((2,3)):<br>
>><br>
>> print('tuple(two, three)')<br>
>><br>
>> elif case(2, 3):<br>
>> print('two or three')<br>
>> elif case > 3:<br>
>> print('more than three')<br>
>><br>
>> else:<br>
>><br>
>> print('unmatched')<br>
><br>
><br>
> Ok, but you have to nest it inside a for loop. Your class is a good<br>
> solution, but a new syntax does not need nesting in a with or a for<br>
> statement.<br>
><br>
<br>
</div>I don't think he *has* to nest it. My reading of the above is that<br>
it's the For-Case Paradigm [1], normally considered an anti-pattern<br>
but viable for demonstrating what happens in each case.<br>
<br>
ChrisA<br>
<br>
[1] <a href="http://thedailywtf.com/Articles/The_FOR-CASE_paradigm.aspx" target="_blank">http://thedailywtf.com/Articles/The_FOR-CASE_paradigm.aspx</a><br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Python-ideas mailing list</span><br><span><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a></span><br><span><a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a></span><br><span>Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a></span></div></blockquote></body></html>