Re:Clever code is probably the worst code you could write
by vlovich123 on Tuesday May 21, 2024 @08:30PM
(#40436005)
Same for Rust.
[ Parent
| on HN ]
Re:Clever code is probably the worst code you could write
by the__alchemist on Tuesday May 21, 2024 @10:38PM
(#40436816)
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.
Re:Clever code is probably the worst code you could write
by cptroot on Wednesday May 22, 2024 @10:39PM
(#40449807)
FYI 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()
Re:Clever code is probably the worst code you could write
by vlovich123 on Thursday May 23, 2024 @04:02AM
(#40451877)
I 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.