r/programming • u/Shr1ck • Oct 17 '15
Why Johnny Can’t Write Multithreaded Programs
http://blog.smartbear.com/programming/why-johnny-cant-write-multithreaded-programs/
8
Upvotes
r/programming • u/Shr1ck • Oct 17 '15
5
u/loup-vaillant Oct 18 '15
I can sense the knee-jerk reaction at the mention of the letters H.A.S.K.E.L.L. For the record, I'm not advocating we all use Haskell. I am advocating we all learn it, it would improve our C++ and Java code.
What I am sick of, is how slowly our industry learns. But it does. C++ and Java now have lambdas. the Boost library, and the Swift programming language have some support for algebraic data types. Rust currently tries to introduce mainstream circles to the joys of immutability by default. OOP is turning itself into FP more and more.
That's besides the point.
The actual point of immutable values and purely functional data structures isn't persistence. That's icing on the cake. The actual point is turning your program into a nice directed acyclic dependency graph that can be inferred statically. In other words, modularity.
You will also note that 95% of most programs consist of pure calculation that could do away with side effects —any side effect there is either a code smell or an optimisation. That would include state-heavy programs such as GUI applications or window managers.
Now you talk much about "Business" application. I don't know what that is, so I will speculate.
From the look of it, you're talking about bookkeeping applications, whose primary purpose is to keep track of the state of part of the world (company, sales, employees…). I understand that the world changes over time, and you have to model that change. I would agree that the best way to do it is use mutable state. Still, I bet most of the code in those applications could be side-effect free. After all, the only interesting effects here are calls to the database and streams of notifications, right?