Design note: pipelines over loops

This note goes with Streams and Pipelines in EK9. EK9 supports both imperative loops and stream pipelines. It steers you to pipelines of small, named functions, even though the loop is often shorter.

The loop is shorter

There is little doubt that the same functionality can be written with much less code in an imperative style. The library example's imperative version is shorter, even before it sorts the author names. For one-off, short, simple processing it may be the better approach. And the functional approach takes more thought to design and implement than a loop with state variables.

But it does not last

Fewer methods on classes

The functional approach reduces the number of methods needed on classes. Small, distinct functions and classes combine in components, compositions and pipelines, rather than many capabilities living inside classes. In general, the smaller, more rounded and better documented the components, the more reliable, reusable and understandable the code is over the longer term.

A choice

EK9 does not remove the imperative style. The minute you need to make a few alterations here and there, though, the pipeline is much easier to alter and change.