What does it mean when code is “easy to reason about”?
Preethi Kasireddy
73629

This expression has been associated with functional programming lately, and mostly with React. And the article is basically saying “easy to reason about“ means having “pure functions”. This is true, but I think the definition could go a bit deeper than that. I think pure functions are a subset of something that is easy to reason about.

Something that is easy to reason about could be something that when operating, you expect to get the most logical result out of it. The pieces in a system are organized in a logical sense (and with good judgement) in a way that your brain to makes sense of it naturally. For example, I don’t really know how a TV works internally, but if I press the red button in the remote. I know the TV will turn on, and if I press it again, it will turn off.

This is different from code that is easy to read. Maybe you can see how a piece of code works but the result of the whole thing might not be something that you would expect logically.

So pure functions are easy to reason about because they don’t do unexpected things behind the scenes, and when you feed them something,
they output exactly what you wanted given that specific input.