Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

IMO the match statement has some very unintuitive behaviour:

    match status:
        case 404:
            return "Not found"

    not_found = 404
    match status:
        case not_found:
            return "Not found"
The first checks for equality (`status == 404`) and the second performs an assignment (`not_found = status`).

`not_found` behaving differently from the literal `404` breaks an important principle: “if you see an undocumented constant, you can always name it without changing the code’s meaning” [0].

[0] https://twitter.com/brandon_rhodes/status/136022610839909990...



I see. Is it fair to say your issue with the feature is less about not wanting the feature and more about the implementation details?


Actually, I don’t really want the feature. It’s complicated and it doesn’t really fit with the rest of the language (it breaks fundamental rules, as above, and has scoping issues).

Worst of all, though, it’s really just another way to write if-elif-else chains that call `isinstance` - a pattern which Python traditionally discouraged in favour of duck-typing.


Aw dang you spoiled it :-) I was hoping my example would be more fun to work through haha.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: