Hacker News new | ask | show | jobs
by Bob2019 3106 days ago
Tried to explain functional programming (in C# because it's a real world job) to a colleague. It's surprisingly difficult to sell benefits of purity and immutability if the there is no threading going on. Much as I hate JavaScript at least those who touch React educate themselves in right concepts (even if they start using funny non-standard CQRS terminology).
1 comments

It really shouldn't be that hard.

The real benefit of purity and immutability is managing complexity. People focus way too much on threading, which is a buzzword. As ever, the buzzwordy version of an otherwise good idea is never all it's cracked up to be.

It's all down to context boundaries:

- With a pure function, you can completely understand its behavior by reading just that function's code, and possibly also the code of any other functions it calls.

- With a method that relies on mutable variables, you have to understand not only that method, but also every other method that mutates the variable, and possibly all the code that has a reference to that object.

In the second case, you've potentially got a much wider scope to understand. Almost as wide a scope as you need to understand when global variables are in use. Worse, it's now possible to change that method's behavior without touching any of that method's actual code. It's even possible that you could change it without touching the file that contains it.

In a nutshell, the real benefit of purity and immutability is that it eliminates "spooky action at a distance" type behaviors, and all the intractability that tends to come with them.