Chapter 4. Writing a real application

 

This chapter covers

  • Putting primitives together to write real code
  • A typical development process
  • Modularity
  • Testability

We’ve introduced FRP with some contrived examples and shown you some more realistic GUI code. Now we want to show you how to write a real-world FRP application, this time in the industrial space. In this chapter, you’ll develop a petrol pump.

It can be difficult to find the right example for FRP. FRP’s pretensions to stardom conglomerate around the notion that it deals with complexity, but this doesn’t manifest in a small example. If the example is too simple, you’ll say, “That was a weird way of doing things for no apparent benefit.” If the example is too big, it can be a lot of work for you. We chose the petrol pump idea to strike a balance: the size is about right, it should be easy to follow because it’s a familiar real-world application, and the level of complexity is enough for our purpose.

Note

This chapter is dense, and we think it will repay the effort you spend on it, but you don’t have to study it closely right now. If it fits your learning style, feel free to read parts of it briefly, carry on with the book, and come back here later.

This example uses industry-standard development methodology: you’ll add features one by one without much deliberate design. We’ve left out refactoring; refactoring is simple in FRP, and we’ll cover this subject in chapter 13.

4.1. The petrol pump example

4.2. Running the petrol pump example

4.3. Code, meet outside world

4.4. The life cycle of a petrol pump fill

4.5. Is this really better?

4.6. Counting liters delivered

4.7. Showing dollars of fuel delivered

4.8. Communicating with the point-of-sale system

4.9. Modularity illustrated: a keypad module

4.10. Notes about modularity

4.11. Adding a preset dollar amount

4.12. What have you achieved?

4.13. Summary