Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The biggest benefit I see is lack of side-effects. With a functional program you can be sure that your can safely call any function without having to worry about the current state of your app.

A proper functional program can start to do very cool things safely: like hot reloading of code. When I'm debugging a Clojurescript app I can have a live running game, and update the physics without even reloading the page. It's all live.

A proper functional program really looks like a series of mappings from a collection of data sources to a collection of data sinks.

The keyword for this is referential transparency: https://www.braveclojure.com/functional-programming/

There are other benefits like composability, designing your programs this way will give you access to algorithms that works otherwise not work with your code. The simplest example is Map, Filter, and Reduce. These functions are by their very nature parallel because a compiler knows that there are no intermediate steps, unlike a for loop.



I should probably add that I program mostly C# so I'm getting Functional benefits like Map and Filter because Eric Meijer added LINQ. He made it his life's work for a few years to bring functional programming to the masses.

But I was minimizing state long before that because state makes any program much harder to understand.

Confessions of a Used Programming Language Salesman: Getting the Masses Hooked on Haskell http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72....


C# might not be the best language to try FP in. F# is a popular alternative that might feel more familiar than e.g. Haskell. Since JS was one of my first languages, I learned a lot just from using the library RamdaJS which helped soften the learning curve for me


Julia gives such beautiful examples for composabilty: Feed 3km+-10m into an algorithm which was written with just numbers in mind and units and confidence intervals often propagate all the way through.


I am finding “lack of side affect” to make reading reloading, updating, game hard to read


Exactly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: