We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Should I I/O?

A program that doesn't do any i/o is pretty useless. What's the point of computing something if you can't see the results?

In functional programming, i/o is viewed as dirty but necessary. We know we can't eliminate i/o from our code, so we just contain it as much as possible. There should be a clear place in your project that does nasty i/o stuff, and the rest of your code can be pure.

For example, a Python program might:

  1. Read a file from the hard drive as the program starts
  2. Run a bunch of pure functions to analyze the data
  3. Write the results of the analysis to another file on the hard drive at the end