How can you do anything useful without mutable state?

I’ve been reading a lot of stuff about functional programming lately, and I can understand most of it, but the one thing I just can’t wrap my head around is stateless coding. It seems to me that simplifying programming by removing mutable state is like “simplifying” a car by removing the dashboard: the finished product may be simpler, but good luck making it interact with end-users.

Just about every user application I can think of involves state as a core concept. If you write a document (or a SO post), the state changes with every new input. Or if you play a video game, there are tons of state variables, beginning with the positions of all the characters, who tend to move around constantly. How can you possibly do anything useful without keeping track of changing values?

Every time I find something that discusses this issue, it’s written in really technical functional-ese that assumes a heavy FP background that I don’t have. Does anyone know a way to explain this to someone with a good, solid understanding of imperative coding but who’s a complete n00b on the functional side?

EDIT: A bunch of the replies so far seem to be trying to convince me of the advantages of immutable values. I get that part. It makes perfect sense. What I don’t understand is how you can keep track of values that have to change, and change constantly, without mutable variables.

20 Answers
20

Leave a Comment