Re:Rust Weird Expressions
by estebank on Friday May 14, 2021 @12:57PM
(#27156535)
I like matching on bools on the same cases where someone wouldn't write braces around the body in C: whenever the corresponding expressions keep you under the line length. For example:
Of course, you'd more likely have something like
[ Parent
| on HN ]
My favorite thing about internationalization is that some languages have 6 different translations for different amounts.
Re:Rust Weird Expressions
by rabidferret on Friday May 14, 2021 @01:11PM
(#27156758)
let plural = match cases.len() {
1.. => "s",
0 => "",
};
;PThat's not the correct plural rule in English, you'd want
let plural = match cases.len() {
0 | 2.. => "s",
1 => "",
};
or something (though to be fair the original code snippet also handled "0" incorrectly -- should be "cases.len() != 1").And also to be fair you probably don't want to be hardcoding English pluralization rules.
Re:Rust Weird Expressions
by rabidferret on Saturday May 15, 2021 @08:01AM
(#27164445)
I used to maintain a library which actually tried to implement proper English pluralization rules. I can confirm you don't want to do that.