4 ms·
I've tried to learn FP a few times, but I never understood the advantages. Most recently, I opened up Armstrong's Erlang book. The power of Erlang seems to be
by psranga 18y ago
I've tried to learn FP a few times, but I never understood the advantages. Most recently, I opened up Armstrong's Erlang book.
The power of Erlang seems to be due to the fact that processes and crashes are part of the language, and the language makes it fast and simple to create processes and handle crashes. This (esp the process part) can be implemented in a non-functional language.
It wasn't obvious to me why the functional nature of Erlang gave it any power.
It seems to me that things like the Erlang book example where they provide reliability to any arbitrary app can be implemented in C++ using a base class + virtual methods.
I would appreciate any "killer articles" which will make me "get it".
- smanek 18y agoIn my experience, the advantage of functional programming is that it is very easy to understand and debug. If my program consists of series of small functions that each have no side effects, things become very straight forward. I won't have one function mysteriously causing problems in another part of the program because it modifies global state in some unexpected way. Combined with decent unit testing to ensure that each small function works as expected, it becomes exceedingly unlikely that changes will introduce difficult to debug issues. One of the best books that first showed me how you can use a lot of the features of functional languages (first class functions, lambdas, etc) to build better functional programs was Norvig's PAIP.
- abless 18y agoFunctional Programming is just beautiful. You can't write beautiful code in C++. Functional Programming, however, is like maths, where you can create and exploit nice structures. It's just beautiful code.
- visitor4rmindia 18y agoOk - I'll give it a shot. :-) Using FP is like learning to ride a bike. It's difficult to give you "advantages" over riding a car (or bus) - you have to try it out and get comfortable to appreciate it. Just give it a try - write out a few of your (semi-serious) projects in an FP language. Start with Scheme. You may enjoy it!
- weavejester 18y agoThe idea behind FP is to minimize or eliminate implicit state change. This has several advantages. The first is that it eliminates errors caused by unexpected state change. This is a larger class of errors than you might expect. The second advantage is that FP applications are easier to unit test. When given a certain argument, FP functions always return the same value, so if f(1) is 2 in your tests, you can be guarenteed it'll be 2 in your application, too. FP generally more predictable. The final advantage I can think of is concurrency. Concurrency in imperative languages is made harder because a data structure referenced by one thread can be mutated by another. In FP, data structures are immutable, so this problem doesn't occur.
- 10ren 18y agoI found this article helpful (see sections 4 and 5) http://web.mac.com/jimbokun/iWeb/Site/Blog/AB35C167-7755-4113-938C-968F65256D76.html http://web.mac.com/jimbokun/iWeb/Site/Blog/AB35C167-7755-411... Have you checked/asked on Stack Overflow? It tends to be good on this kind of question. Basically, I think functional programming is a particularly good match for some problems (e.g. tree transformation) and for proving theorems. So, like every technique, it's good to have in your toolbox if it's not too expensive for you to acquire. Apart from that, it's a matter of taste/religion. For issues like global variables, it's considered good practice to avoid them in imperative languages too. For example, Java/C++ have private/public/protected access modifiers to help you manage this. I too read Armstrong's book, and concluded same: Erlang's concurrency power is due to pure-message passing, not due to it being functional. The processes could be written imperatively, and provided the communication was pure-message passing (and you tuned the implementation as the Erlang team did), you'd get the same benefits. BTW: I like to think of Guy Steele, who co-invented Scheme (used in SICP), and also co-wrote the Java Language Specification.