You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the refactoring_imperative_to_functional exercise, the solution computes avg_power in one iterator pass, max_temp in a second, then partitions servers by health in a third explicit for loop — three passes total over the fleet. The imperative version does all three in a single pass, making it objectively faster by a 3× constant factor.
The comment correctly notes that the three-way partition "is BETTER as a loop", but the same reasoning applies to the scalar aggregates: splitting them into separate iterator chains comes at a performance cost that goes unacknowledged. If the goal is to show when functional style is appropriate, the example would be stronger if it either used a single-pass fold (to demonstrate functional style done right) or explicitly called out that the hybrid approach trades some performance for readability in the aggregate computations.
As it stands, the solution is neither more readable nor more performant than the imperative version, which may leave new learners with a misleading impression of what functional style offers in Rust.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In the refactoring_imperative_to_functional exercise, the solution computes
avg_powerin one iterator pass,max_tempin a second, then partitions servers by health in a third explicit for loop — three passes total over the fleet. The imperative version does all three in a single pass, making it objectively faster by a 3× constant factor.The comment correctly notes that the three-way partition "is BETTER as a loop", but the same reasoning applies to the scalar aggregates: splitting them into separate iterator chains comes at a performance cost that goes unacknowledged. If the goal is to show when functional style is appropriate, the example would be stronger if it either used a single-pass
fold(to demonstrate functional style done right) or explicitly called out that the hybrid approach trades some performance for readability in the aggregate computations.As it stands, the solution is neither more readable nor more performant than the imperative version, which may leave new learners with a misleading impression of what functional style offers in Rust.
Beta Was this translation helpful? Give feedback.
All reactions