3 ms·
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
by thidr0 6y 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.
- ben509 6y agoThe 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.
- rytill 6y agoI have never really pushed hard on style in my software journey. But this is different. That code sample is horrifying.
- arnvald 6y agoI 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