Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 06-12-2017, 01:41 AM   #1
leavesofliberty
Pooh-Bah
 
leavesofliberty's Avatar
 
Join Date: Jul 2010
Location: enrolled at groovynomics u
Posts: 5,366
Question Food for Thought: Functional Programming

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?
leavesofliberty is offline   Reply With Quote
Old 06-12-2017, 12:50 PM   #2
daveT
S.A.G.E. Master
 
daveT's Avatar
 
Join Date: Jun 2005
Location: Why didn't I use Clojure instead?
Posts: 21,394
Re: Food for Thought: Functional Programming

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.
daveT is offline   Reply With Quote
Old 06-12-2017, 01:31 PM   #3
candybar
old hand
 
Join Date: Aug 2011
Posts: 1,596
Re: Food for Thought: Functional Programming

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.
candybar is offline   Reply With Quote
Old 06-12-2017, 04:53 PM   #4
leavesofliberty
Pooh-Bah
 
leavesofliberty's Avatar
 
Join Date: Jul 2010
Location: enrolled at groovynomics u
Posts: 5,366
Re: Food for Thought: Functional Programming

Thank you peeps. Very helpful! I don't need to consider a re-write now. WHEW.
leavesofliberty is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 04:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ę 2008-2010, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online