|
|
Log in / Subscribe / Register

"Structural pattern matching" for Python, part 2

"Structural pattern matching" for Python, part 2

Posted Sep 1, 2020 20:26 UTC (Tue) by NYKevin (subscriber, #129325)
Parent article: "Structural pattern matching" for Python, part 2

I still think indentation is a problem here. If you're following PEP 8, then you have four spaces of indents for the match clause, four spaces for the enclosing case, four spaces for the enclosing function, and (possibly) four spaces for the enclosing class. That's a quarter of the entire line just devoted to indentation. Then, if you want to put this thing inside of a loop or other block, it gets even worse. So, basically, the only way this will be readable is if it's doing some kind of top-level dispatch, where it destructures into local variables, and then immediately hands those variables off to another function or method. That's probably somewhat useful, in certain contexts (e.g. consuming an AST and dispatching on the atom type) but now I get this strange feeling that we're basically reimplementing the vtable, in a language that already has very elaborate support for polymorphism and OOP.

But maybe I just haven't studied it enough.


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds