what are the benefits of learning a functional programming?

I am learning scala which a mix of both programming model (OO and functional) I am wondering what are the benefits of functional programming language.

I am confused on what approach I should take, mainly its about what components I should keep functional and which ones I should code in a regular OO way.

I was trying to write a simple chat server in scala. ( I may be wrong but I guess chat server kind of application may not require the complexity / constructs scala has to offer)

Posted Apr 7, 2013, 3:11 PM UTC

04
343346E•

Sure, most programs don't require every single feature in Scala, or C++, or a lot of other languages...

One example is the pattern matching.

http://www.scala-lang.org/node/123:

If the selector of a pattern match is an instance of a sealed class, the compilation of 
pattern matching can emit warnings which diagnose that a given set of patterns is not 
exhaustive, i.e. that there is a possibility of a MatchErrorbeing raised at run-time.

This can be used to avoid things like null pointer exceptions, if you use Option instead of nulls.

The message passing between local and remote nodes in Scala is also pretty neat. You should be able to write a chat server with less code in Scala than in any other language, since you really don't have to deal with the networking stuff, if this is just over a lan.

http://www.scala-lang.org/docu/files/actors-api/actors_api_guide_6.html
2
baconator81•

LISP is a functional language.. And it's widely use for AI.

But I think the great advantage of learning functional programming is that there is a strong push for a lot of system to start supporting functional language mostly because it's very multi-thread friendly. The idea is that unlike structured language (Java/C++), functional language has no state, so it is readily thread friendly.

1
[deleted]•

[deleted]

1
alphabytesOP•

hey that's great that i do not have to worry about the threads much. so i guess chat server will indeed benefit from the thread safety scala provides. but how does it do for web based programming? i mean how does it scale? i am sorry if i am asking silly questions but i am unable to visualize the architecture of any web application using scala.

what i am after is a simple chat server having multiple clients(it can be anything web page, desktop application, mobile) and was specifically interested in the webpage model. i just took up the project to learn this language. or should i start with different project suitable to functional programming.

1
[deleted]•

[deleted]

2
alphabytesOP•

thanx nice video.

1