So, you’ve begun to dabble in functional programming. It won’t be long before you come across the concept of pure functions. And, as you go on, you will discover that functional programmers appear to be obsessed with them. “Pure functions let you reason about your code,” they say. “Pure functions are less likely to start a thermonuclear war.” “Pure functions give you referential transparency”. And on it goes. They are not wrong either. Pure functions are a good thing. But there’s a problem…
A pure function is a function that has no side effects.1 But if you know anything about programming, you know that side effects are the whole point. Why bother calculating ? to 100 places if there’s no way anyone can read it? To print it out somewhere, we need to write to a console, or send data to a printer, or something where someone can read it. And, what good is a database if you can’t enter any data into it? We need to read data from input devices, and request information from the network. We can’t do any of it without side effects. And yet, functional programming is built around pure functions. So how do functional programmers manage to get anything done?