<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.hljs-function
{mso-style-name:hljs-function;}
span.hljs-keyword
{mso-style-name:hljs-keyword;}
span.hljs-title
{mso-style-name:hljs-title;}
span.hljs-params
{mso-style-name:hljs-params;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:27921548;
mso-list-type:hybrid;
mso-list-template-ids:922393548 -1 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:\F0D8;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;
mso-fareast-font-family:"Times New Roman";
mso-bidi-font-family:"Times New Roman";}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l1
{mso-list-id:299772500;
mso-list-type:hybrid;
mso-list-template-ids:29238832 -1 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l1:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:\F0D8;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;
mso-fareast-font-family:"Times New Roman";
mso-bidi-font-family:"Times New Roman";}
@list l1:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l1:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l1:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l1:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l1:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l1:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l1:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l1:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l2
{mso-list-id:1612930434;
mso-list-type:hybrid;
mso-list-template-ids:535086530 -1 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l2:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:\F0D8;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;
mso-fareast-font-family:"Times New Roman";
mso-bidi-font-family:"Times New Roman";}
@list l2:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l2:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l2:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l2:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l2:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l2:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l2:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l2:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l3
{mso-list-id:1970086380;
mso-list-type:hybrid;
mso-list-template-ids:7744364 -1 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l3:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:\F0D8;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;
mso-fareast-font-family:"Times New Roman";
mso-bidi-font-family:"Times New Roman";}
@list l3:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l3:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l3:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l3:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l3:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l3:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l3:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l3:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style></head><body lang=RU link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span lang=EN-US>Interesting PEP. Actually it reminds me Crystal language ‘case’. But I have some comments<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=EN-US>> </span>An excerpt from PEP622 [1]:</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>> Let us start from some anecdotal evidence: isinstance() is one of the</p><p class=MsoNormal>> most called functions in large scale Python code-bases (by static</p><p class=MsoNormal>> call count). In particular, when analyzing some multi-million line</p><p class=MsoNormal>> production code base, it was discovered that isinstance() is the</p><p class=MsoNormal>> second most called builtin function (after len()). Even taking into</p><p class=MsoNormal>> account builtin classes, it is still in the top ten. Most of such</p><p class=MsoNormal>> calls are followed by specific attribute access.</p><p class=MsoNormal>> </p><p class=MsoNormal>> There are two possible conclusions that can be drawn from this</p><p class=MsoNormal>> information:</p><p class=MsoNormal>> </p><p class=MsoNormal>> * Handling of heterogeneous data (i.e. situations where a variable</p><p class=MsoNormal>> can take values of multiple types) is common in real world code.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=EN-US>It can be handled with modern Python’ types.</span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>> * Python doesn't have expressive ways of destructuring object data</p><p class=MsoNormal>> (i.e. separating the content of an object into multiple variables).</p><p class=MsoNormal>> </p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=EN-US>Actually the second reason when isinstance() is used (related to “destructuring”) is the case with inheritance. So the isinstance() switches cases between different successors of some base class. And there would be such a kind of “destructuring”:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span lang=EN-US>if isinstance(something, Window): return something.handle<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span lang=EN-US>elif isinstance(something, Button): return something.wnd_hnd<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span lang=EN-US>else: raise SomeError(“blah-blah”)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>which is anti-pattern sure: in the case of inheritance, the getters must be delegated to concrete implementations.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal>> I just want to say a big thank you to the Haskell creators for giving</p><p class=MsoNormal>> us a tool to efficiently write real world code (as it is called above).</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=EN-US>The reason why ML family languages have pattern-matching is:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US> data X = X1 Int Int | X2 String<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=EN-US>Python and similar languages don’t support algebraic data types directly (and usually you simulate it with inheritance), so you don’t need pattern-matching and such a way of “destructuring” at all. What is<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US> case x of X1 n m -> …<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>? It’s a leak of abstraction. A leak of knowledge about INTERNAL structure, internal representation of the object, which is bad. So, if you think that pattern-matching is very good (aka “real world”) , IMHO you are not right here. So C# designers added EXPLICIT support of deconstruct:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal style='text-indent:36.0pt'><span class=hljs-keyword>private</span><span class=hljs-function> </span><span class=hljs-title>static</span><span class=hljs-function> (</span><span class=hljs-keyword>string</span><span class=hljs-params>, </span><span class=hljs-keyword>int</span><span class=hljs-params>, </span><span class=hljs-keyword>double</span><span class=hljs-function>) </span><span class=hljs-title>QueryCityData</span><span class=hljs-function>(</span><span class=hljs-keyword>string</span><span class=hljs-params> name</span><span class=hljs-function>)</span><span class=hljs-function><span lang=EN-US> {…}</span><o:p></o:p></span></p><p class=MsoNormal><span class=hljs-function><o:p> </o:p></span></p><p class=MsoNormal><span class=hljs-function><span lang=EN-US>so you don’t leak information about internal representation of your data and use just common external general representation like tuples, for example. The second helper in C# is a new `switch` syntax, which is very close to pattern-matching, but again: it’s limited with public fields, so only a developer decides which part of his class will be available for matching, and no any leak again. This idea was crystallized in Perl: you don’t know what is the object but do know that it can be used in scalar context/list context/hash context and so on. In OOP, for example, you don’t know what is the object but you know that you can use it as a container of items, which can be enumerable/modifiable-in-place/whatever… This is a right solution from a language designer point of view, but not a ML-style pattern matching.<o:p></o:p></span></span></p><p class=MsoNormal><span class=hljs-function><span lang=EN-US><o:p> </o:p></span></span></p><p class=MsoNormal><span class=hljs-function><span lang=EN-US>And this understanding is often used in Haskell too – some types are “hidden” for the user: you have only smart constructors/getters but not knowledge about inner structure of the object. IMHO ML-style pattern matching is outdated feature, more typical for 70-80s languages.<o:p></o:p></span></span></p><p class=MsoNormal><span class=hljs-function><span lang=EN-US><o:p> </o:p></span></span></p><p class=MsoNormal><span class=hljs-function><span lang=EN-US>---<o:p></o:p></span></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt'>Best regards, Paul</span><span style='font-size:10.0pt'><o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>