I'm a software architect/consultant in Boulder, Colorado. I started blogging at: http://wayne-adams.blogspot.com/, but have since started the new blog, Data Sceintist in Training which will cover the areas I am learning as part of my own "big data" training, including the Hadoop family, frameworks like OpenStack, the R programming language, column-oriented databases and the art of examining data sets for useful patterns. The original blog will be kept alive with Java-specific posts. Wayne is a DZone MVB and is not an employee of DZone and has posted 35 posts at DZone. You can read more from them at their website. View Full User Profile

OO to FP: Transition

10.26.2011
| 3693 views |
  • submit to reddit
For the last year or so, I've been trying to come up to speed on functional programming, studying bits and pieces here and there. One interesting source was Bruce Tate's Seven Languages in Seven Weeks, which included a number of FP languages. I reviewed the book on this blog -- in seven days -- a few months ago, if that tells you how much time I've devoted to this topic in general! I've decided to get a little more serious now.

Since I've been doing primarily object-oriented development for many years, I have a perspective that is different than someone just learning to program. I think that a person with an OO background might need a slightly different introduction to FP than someone coming in with a clean slate -- it certainly seems that way to me, as I don't feel a lot of the "intro" material emphasizes the differences that an OO person would find important. The point of my posts on this topic is to capture my own experience learning FP before I forget what my "angle" was (and then myself become useless to an OO person about to go through the same process).

This experience reminds me of my last development paradigm shift, when a number of my co-workers and I decided to learn object-oriented analysis, design and programming (in those pre-agile days, huge emphasis was placed on the difference between those three phases!). I worked in a research lab, and we wrote mostly in C and Fortran. Some of use wanted to become really grounded in OOA/D/P before we started writing code (I was in this camp) and some of us just wanted to start hammering out code. I could not understand these people in the latter camp. How could you develop object-oriented code without learning what object-oriented analysis is? And you're not even going to learn about OOD? You're skipping the analysis and design phases? You're just going to be writing Fortran code in C++! Ahh! I was young and thought I would live forever. Actually, I thought about death a lot (actually, I didn't).

We used Smalltalk and C++. Although I was really happy with my Smalltalk tic-tac-toe program (on a Mac), I knew from the beginning that this platform was not going to rule the OO world. C++ had a lot going for it (and still does): it was a bridge technology from C to object orientation, and the results speak for themselves. Of course Java has been hot for many years, too, but frankly I suspect that the success C++ had in bridging procedural developers to OO may have been the big enabler for Java.

One thing about FP: I'm not sure I see an equivalent bridge technology; not an out-of-the-park winner, at least. I appreciate the FP-inspired languages that run on the JVM; the JVM seems like a potential bridge technology. For example, I could probably convince my co-workers to accept some Scala code on our Java platform. But I don't feel very enthused working with Scala. If you read my posts on Seven Languages in Seven Weeks, you know I like Erlang a lot. I've spent a lot of time learning Erlang, but I'm just now giving up on it for a number of reasons, the main one being that I just don't see it becoming a Java or a C++. I don't feel particularly competent in my ability to predict which FP language is likely to prevail, though. I won't be surprised by what happens, but I also know it won't be something I could have predicted, as things seem a little less clear-cut than the competition between OO languages years ago.

So, here is what I have decided to do: I'm going to learn Haskell, using the O'Reilly book Real World Haskell. My goal is to get a good education in functional programming and not to worry at this time about who's going to "win", and I feel Haskell is a great language to choose to learn FP. As I learn, I'll collect my thoughts and mention what jumps out at me, as an OO person, and hopefully some other OO people will find the commentary useful.

I don't hold strong opinions on any of these topics. Mostly I just want to learn FP and hopefully help other OO developers do the same. I would also like to be especially proficient in one FP language, so I've made my choice. If you are interested in Haskell, or are a Java developer interested in FP, I hope I provide something useful to you. My first post is coming in a couple of days.

 

From http://wayne-adams.blogspot.com/2011/10/oo-to-fp-transition.html

Published at DZone with permission of Wayne Adams, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Robert Csala replied on Thu, 2011/10/27 - 3:57am

Without saying that it would be future bridge between OOP and FP, I think Python is a good language to start with OOP (or even procedural, for that matter) and learn FP in the same language. Imho, Scala is not the right tool for learning this (too complex, too cryptic), but might work very well after you've made the transition.

Kieron Wilkinson replied on Thu, 2011/10/27 - 7:25am in response to: Robert Csala

Scala has many features in it's standard library, that doesn't necessarily make it complex or cryptic. We actually used it to greatly simplify the applications we write, both in terms of code size, and readability. Our student placement, who has only done 2 years of Java at Uni, has taken to it very easily, if that is any measure. You can write complicated code in any language. Some people write complicated code in Scala. That does not make Scala itself complicated. In fact I'd say Java is pretty complicated in terms of syntax, because of all the inconsistencies (we've all just got used to them). If you don't like the more complicated features, don't use them. We use coding standards for doing exactly that.

Robert Craft replied on Thu, 2012/01/26 - 5:55am

Functional program has been treated like a religion for quite some time, but in reality it is more of a style. Just like Object Oriented programming. The best way to get get started using functional programming is to just write code. I highly reccomend taking a stab at Project Euler problems in any functional language as a starting point. But since functional programming in most common languages (C++, C#, Java) is difficult, I would reccomend learning a multi-paradigm language. (One which does OO and Functional, as a way of learning functional programming without jumping off the deep end.) Coming from Java, Scala seems like the most resonable choice. And for .NET developers coming from a C# background, F# is the way to go.

Spring Security

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.