O'Reilly logo

Programming Elm by Jeremy Fairbank

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Prevent Invalid States

You can drastically improve the salad builder’s maintainability with one final tweak. The application uses four fields to represent view state: building, sending, success, and error. In this section, you will see how invalid configurations of these fields could lead to ambiguity and bugs. Then, you will fix the issue by consolidating the fields into one.

Combine the Fields

Here’s the problem: the four view state fields encapsulate one possible view state. Inside viewStep, you check the fields in an arbitrary order with if-else to pick what to display. First, you check sending and then building. You never bother checking the success field and you assume it’s True in the else branch.

That means you could display viewConfirmation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required