3 ms·
I tend to use for loops in Rust for this reason; simple, and understandable by anyone who's programmed in an imperative language. The one-liner approach tends
by the__alchemist 2y ago
I tend to use for loops in Rust for this reason; simple, and understandable by anyone who's programmed in an imperative language.
The one-liner approach tends to include an explicit type declaration (Or turbofish), `iter()`, and `collect()`, at minimum.
- cptroot 2y agoFYI I think you've misinterpreted the parent. To my eyes it looks like they're agreeing that Rust makes summing a list easy using combinations. For example, this is how I would do it in Rust: x.iter().sum()
- vlovich123 2y agoI think they’ve understood and are claiming that a simple loop is cleaner than what you wrote. I’m not sure how since that 1 line communicates what’s happening at a high level with 1 word “sum” whereas a loop requires me to read the loop to confirm it’s a plain summation. This sounds like someone complaining that the concepts they learned when they were first starting out are the only concepts that programming languages should introduce which is silly - technology evolves as we find better and new ways of accomplishing old tasks.