Hacker News new | ask | show | jobs
by thidr0 1959 days ago
Pattern matching is one of my favorite things about Haskell. But seeing it done here in a dynamically typed language is a more than little clunky (three indents needed to get to an expression). It would be better to be matched on the parameter list, but again Python’s typing would make that too difficult.
2 comments

I think it works very well in Elixir which is also dynamically typed. It was there since the beginning though and it's more than just a "match/case" construct, it's built deep into the core of the language, so maybe that makes a difference
The two-space compromise might work:

    def handle(command):
        match command.split():
          case ["quit"]:
            print("Goodbye!")
            quit_game()
          case ["look"]:
            current_room.describe()
It'll be a bit odd, though.
I have never really pushed hard on style in my software journey. But this is different. That code sample is horrifying.