top | item 44982440

(no title)

M0r13n | 6 months ago

Personally, I have never liked the PEP 634 pattern matching. I write a lot of code in Python. 99% of the time when I could use pattern matching, I am going to use simple if statements or dictionaries. Most of the time, they are more straightforward and easier to read, especially for developers who are more familiar with traditional control flow.

discuss

order

Balinares|6 months ago

Dictionaries with a limited key and value type definition are fine, but dictionaries as a blind storage type are a recipe for crashing in prod with type errors or key errors. Structural pattern matching exists to support type safety.

I'll argue that code is in fact not easy to read if reading it doesn't tell you what type an item is and what a given line of code using it even does at runtime.

NeutralForest|6 months ago

You should use if statements if that's what you need. The match statement is for structural pattern matching mostly.

Q6T46nT668w6i3m|6 months ago

What’s the problem using it as a switch statement if you care about typographic issues? I do this so I’d like to know if I missed something and this is a bad practice.

odyssey7|6 months ago

Having user other languages after finishing university studies, Python does not spark joy.