Now with more specific catch-call case https://github.com/rust-analyzer/rust-analyzer/pull/4204 …pic.twitter.com/RX8T9oHOvH
-
-
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
you and clippy are going to have a wrestling match over that one
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
it's also infinitely more scalable, since it's easy to just add more cases
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
It depends. If the contents of your match arms are small. Otherwise the code suffers more rightwards drift with match.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I think the only advantage of if-let over match is it adds less indentation to the RHS. Mostly I prefer match without a "catch-all", I explicitly list constructors in an or-pattern so that I wont' forget to update the code if I add a new constructor.
-
Yeah, avoiding catch-all is a good thing. Doing that too.
End of conversation
New conversation -
-
-
I agree. I use if let only when without else.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Not always. With long expression and short arms (like your example), probably. But with short expression and a lot to do in arms, probably if/else is more readable. Case by case basis.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Definitely! If we really need the “else” it’s more appropriate to use match with two or more arms
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I had this discussion today with a colleague who doesn’t have Rust experience, and he found the if let variant more readable (despite it being longer)
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.