Pipe madness?

Unnecessary from what perspective?

remaining_time = max(0, interval - elapsed_time)

Sure the computer doesn’t need it but:

p. 15, Refactoring: Improving the design of existing code; 1999

The right hand side of the assignment focuses on what needs to be done - the left hand side enlightens us why it’s being done.

Sometimes I wonder whether these “idioms” date back to when this was normal

z = max(0, x - y)
schedule_events(z)

That z is unnecessary.

Pipes can be similarly affected by bad or lack of naming which is what is really going on in the OP.

interval
|> calc_remaining_time(time_elapsed)
|> make_positive_value()
|> schedule_events()

which should really become

interval
|> remaining_time(time_elapsed)
|> schedule_events()

but even that seems forced compared to

remaining_time = max(0, interval - elapsed_time)
schedule_events(remaining_time)
3 Likes