Open Side Menu Go to the Top
Register
Food for Thought: Functional Programming Food for Thought: Functional Programming

06-12-2017 , 01:41 AM
Here's an article I've been grunching over after reading another thread.

There seems to be a compelling case to use the functional programming paradigm. The author claims that since processors are tapering in their increase in speed that efficient use of concurrency (since now there's multiple processors on a core) means functional programming to get the most out of processors.

Quote:
Concurrency

A functional program is ready for concurrency without any further modifications. You never have to worry about deadlocks and race conditions because you don't need to use locks! No piece of data in a functional program is modified twice by the same thread, let alone by two different threads. That means you can easily add threads without ever giving conventional problems that plague concurrency applications a second thought!

If this is the case, why doesn't anybody use functional programs for highly concurrent applications? Well, it turns out that they do. Ericsson designed a functional language called Erlang for use in its highly tolerant and scalable telecommunication switches. Many others recognized the benefits provided by Erlang and started using it. We're talking about telecommunication and traffic control systems that are far more scalable and reliable than typical systems designed on Wall Street. Actually, Erlang systems are not scalable and reliable. Java systems are. Erlang systems are simply rock solid.

The concurrency story doesn't stop here. If your application is inherently single threaded the compiler can still optimize functional programs to run on multiple CPUs. Take a look at the following code fragment:

String s1 = somewhatLongOperation1();
String s2 = somewhatLongOperation2();
String s3 = concatenate(s1, s2);

In a functional language the compiler could analyze the code, classify the functions that create strings s1 and s2 as potentially time consuming operations, and run them concurrently. This is impossible to do in an imperative language because each function may modify state outside of its scope and the function following it may depend on it. In functional languages automatic analysis of functions and finding good candidates for concurrent execution is as trivial as automatic inlining! In this sense functional style programs are "future proof" (as much as I hate buzzwords, I'll indulge this time). Hardware manufacturers can no longer make CPUs run any faster. Instead they increase the number of cores and attribute quadruple speed increases to concurrency. Of course they conveniently forget to mention that we get our money's worth only on software that deals with parallelizable problems. This is a very small fraction of imperative software but 100% of functional software because functional programs are all parallelizable out of the box.
The rest of the article is both intimidating and interesting. Here's some discourse on StackOverflow.

What's the outlook of functional programming over the next ten years?
Food for Thought: Functional Programming Quote
06-12-2017 , 12:50 PM
Well, Joe Armstrong says that Erlang is an OO language. Message passing is the main idea of Kay's thinking of OO.

https://www.infoq.com/interviews/johnson-armstrong-oop

FP does not solve concurrency. That's a strange myth that somehow got around, but it suffers from the exact same issues as OO. This has been known for 40 years now.
Food for Thought: Functional Programming Quote
06-12-2017 , 01:31 PM
FWIW, the author of that article is a co-founder of RethinkDB (written in C++) and had very little experience at the time the article was written. If you go to the index, this is how he describes that article:

Quote:
I wrote these a long time ago. I was much more naive then about the craft of software engineering, so proceed with caution.

19 Jun 2006 » Functional Programming For The Rest of Us
08 May 2006 » The Nature of Lisp
It does read like something a really smart college student with little real world experience would write.
Food for Thought: Functional Programming Quote
06-12-2017 , 04:53 PM
Thank you peeps. Very helpful! I don't need to consider a re-write now. WHEW.
Food for Thought: Functional Programming Quote

      
m