4 ms·
I'm overall a rust fan but I've always agreed with you about `if let`. What I don't like is that it reads right-to-left and starts getting awkward if either sid
by ntoskrnl 4y ago
I'm overall a rust fan but I've always agreed with you about `if let`. What I don't like is that it reads right-to-left and starts getting awkward if either side is much longer than just a variable name.
if let Some(Range { start, end }) = self.calc_range(whatever, true) {
// ...
}
I feel it would read much smoother if you switched the two sides so execution flows left-to-right
if self.calc_range(whatever, true) is Some(Range { start, end }) {
// ...
}
- mpawelski 4y agoAgree, this is something that I wish was changed and it's something that C# got right. I think I tried to look up why this syntax was chosen and found some old github issues when people were actually suggesting the latter syntax (pattern on the right) and I think there were some syntax ambiguities in this syntax. Not sure if this was the main reason. Maybe the lang team just didn't thought the difference is important enough (and it is for me! ;-)). C# lang designers think about IDE experience when designing language syntax (that's why we have "from", "where", "select" order in LINQ, for better IDE code completion), hope other language designers were more thoughtful about it too.
- metaltyphoon 4y agoAgreed and that' how C# does pattern matching on `if`