Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Functional programming applied

I have been interested in programming all my life and for the past 6 years I have worked almost exclusively with Java. I just finished with my University studies and have a job as a Java developer for a company.

All these years programming has been a hobby and a favorite past time, but this had a slightly negative effect in the sense that i grew so accustomed to Java i never ventured beyond it as a programming language. I did try to expand my knowledge of things by learning regular expressions, SQL and studied a bit of XML but i could never get involved enough with a new language to learn how to use it properly party because they all look alike so much at their core, i found the learning curve of every new language irritating. I felt like i had to go through the whole process to end up right were i started as i felt that other imperative languages had nothing more to offer me (i know this statement can start a fight, it is not my intention).

I therefore decided at one point to explore the magical world of functional programming. I begun reading a book on Haskel and found it really interesting from an academic point of view (i majored in Mathematics) but could not find practical applications of it to get me going enough to learn the language.

So now that Java is the main part of my day since i am getting paid to code in it (and i enjoy it as much as i did when it was simply a hobby) i felt the need again to broaden my horizons and again functional programming seems like a good idea.

I thought i would start with Scala since i am Java literate (make the transition easier and be more reusable since they can "talk" to each other) and so my question is : In your experience does learning a functional language "make sense"? Are there any real life applications where knowing this paradigm may come in handy? Not only for personal entertainment but also would this be a "pro" in the industry?

like image 437
Savvas Dalkitsis Avatar asked Jul 22 '09 20:07

Savvas Dalkitsis


4 Answers

In my opinion learning functional programming it is not only a good idea because it makes you a better programmer (think which I agree, of course) but because it seems it will become very popular in a near future.

A lot "gurus" are saying that it will be the only way to keep Moore's law alive. Computer clock speed has reach a top and the only way to improve processors speed will be adding more and more cores. In this scenario functional programing becomes handy because in those languages data is immutable and that makes them very easy to paralelize (it can be done automatically actually).

You might want to have a look to the next references

  • Free lunch is over: An excellent and famous article by Herb Sutter explaining the Moore's law issue
  • It's Time to Get Good at Functional Programming: a Dr Dobbs post regarding this subject
  • InfoQ comparison between Erlang and Scala
  • A presentation about F# that also mentions this issue

Buff, I hope it wasn't too bored, ;-)

like image 125
javier-sanz Avatar answered Nov 12 '22 09:11

javier-sanz


Learning a functional language is a big plus, regardless of whether or not you ever use it in your day job. Consider the following:

  1. One of the biggest recommendations for successful concurrent programming is to avoid mutable state in your threaded objects whenever possible. Functional programming teaches you how to do this.
  2. Most functional programmers, once they get over the not-insubstantial learning curve, claim that their techniques make them far more productive than they can be in standard imperative languages. Their code is more bug-free, and a fraction of the size as that of other languages. Think of the productivity boost you got when you finally understood regular expressions. Now put that on steroids. That's what FP can feel like.
  3. Functional techniques are rapidly making their way into imperative programming. Think closures in C#, and Javascript, and soon (maybe, if we're lucky) in Java. It's very likely the two worlds will soon come together.
  4. Finally, in job interviews, knowing a functional language will help you stand out from your average J2EE/.NET clone. It marks you as a self-starter, a disciplined learner, and a passionate programmer -- whether or not you actually are any of these things. Just don't become yet another slathering Scala fanboy, scolding your soon-to-be boss about how he's missing out on the best programming techniques since... you get the idea. It's never good to insult a prospective employer.

For me, studying Haskell has made programming a lot more fun than it used to be. It may do the same for you as well. Good luck!

like image 38
rtperson Avatar answered Nov 12 '22 09:11

rtperson


Functional programming has been making inroads in the financial sector. Which isn't really all that much surprising, if you consider financial analysts have been "programming" in Excel for years, and that's essentially a functional paradigm (more precisely, functional reactive).

So, yes, knowing functional programming can open a few doors just OO can't, and such jobs can be very interesting.

Speaking strictly as a Java programmer, you'll learn techniques you can employ in Java in your day-to-day (though you'll want a better Collections library). Techniques which will decrease the amount of bugs in what you code, make it easier to multithread and multitask, and bring your code closer to the business rules it is implementing than the mechanics of it's implementation.

Now, there are other reasons to learn Scala in particular. Those above, though, are my reasons you may want to learn functional programming.

like image 2
Daniel C. Sobral Avatar answered Nov 12 '22 11:11

Daniel C. Sobral


Learning a functional language definitely makes sense. As Eric Raymond says, if you learn a functional language, it will make you a better programmer in the language of your choice.

From an industry perspective, if you can write good code in a functional language such as Haskell or Objective Caml, you will suddenly be in very high demand for a very small number of positions. It's not clear whether any sensible person would consider this a 'pro', but there are certainly a few very interesting companies that have openings that are for functional programmers only.

like image 1
Norman Ramsey Avatar answered Nov 12 '22 09:11

Norman Ramsey