|
|
Log in / Subscribe / Register

"Structural pattern matching" for Python, part 1

"Structural pattern matching" for Python, part 1

Posted Aug 6, 2020 16:28 UTC (Thu) by mb (subscriber, #50428)
In reply to: "Structural pattern matching" for Python, part 1 by flussence
Parent article: "Structural pattern matching" for Python, part 1

> This comment's misinformed complaining

These were just quotes from the article. How can that be misinformed?
I'm fully aware that there are alternative spellings in the article for the examples I picked from the acticle, but I just wanted to comment on the worst ones. That doesn't mean I agree with the alternatives, though.

> Perl/Raku's equivalent given/when syntax looks nowhere near as terse, unreadable or alien as these cherry-picked examples.

I did not (want to) compare the exact features from the examples to Perl's equivalents.
I just said that the constuct of using magic variables (_) or operators (?) is Perl-like and not very Pythonic.

> I'll agree that they are horribly shoehorned in and out of place though.

Ok. So you basically agree with me.

> That's what happens when your language doesn't evolve for 15 years

Erm, it'd call _that_ misinformed, indeed.
Literally dozens of major good features have been integrated in the past 15 years.
One of the most recent ones being f-strings, for example.


to post comments

"Structural pattern matching" for Python, part 1

Posted Aug 7, 2020 11:56 UTC (Fri) by flussence (guest, #85566) [Link] (1 responses)

> Literally dozens of major good features have been integrated in the past 15 years.
> One of the most recent ones being f-strings, for example.

Look up Perl's format() function. You won't find many uses of that in modern code, because the community collectively realised some time in the 20th century that making people carry the cognitive load of a loquacious bespoke sublanguage that duplicates half of printf (and then doesn't even fix strftime) is absolutely bananas.

And f-strings are explicitly runtime-evaluated. You don't even get constant-folding!

"Structural pattern matching" for Python, part 1

Posted Aug 7, 2020 13:41 UTC (Fri) by excors (subscriber, #95769) [Link]

Perl's documentation introduces "format" as being based on FORTRAN, BASIC and nroff, so it's hardly surprising that it doesn't attract many users nowadays. (https://perldoc.perl.org/perlform.html)

f-strings sound a lot more like Perl's interpolated strings (f"Hello {name}" vs "Hello $name") which are widely used, plus they have nicer syntax when embedding expressions (f"HELLO {name.upper()}" vs "HELLO @{[ uc $name ]}", the latter being a horrific but common Perl idiom). They've also got the printf-ish format specifiers which I doubt I'd be able to use without checking the documentation every time, but f-strings seem useful even without that.


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