Intro


Last week at sapteched Barcelona I did an expert networking session on functional programming. The talk was meant to make clear why this functional style of programming has been gaining popularity since about a decade, and how to get started with functional programming. The ‘why’ was explained using some slides, the ‘how’ by some live coding in Haskell, one of the most ‘pure’ functional languages available today.

Since a lot has been written about these topics already I’m not going to reiterate too much here. The purpose of this blog post is to show some pointers to relevant materials.

Why?

So, why should a developer be interested in functional programming? The answer is basically multi-core processors, and our inability to write decent imperative concurrent applications that make use of these multiple cores. Functional programming can and does help, because it enforces (or at least encourages) immutability. Without mutable state it’s much easier to write concurrent programs. A longer explanation exactly along these lines can be found here.

For further reading I recommend Herb Sutter’s Welcome to the Jungle, and even more his older piece The Free Lunch is over. Another post that’s worth reading is Chris Whealy ‘s “Why We Find Concurrency So Hard – Programming on a Multicore Machine with a Single-core Mindset“.

Shameless plug: Language Ramblings is a new blog by Chris, DJ Adams and myself (though I’ve yet to write my first post over there), targeting (SAP) developers who’re also interested in the functional style of programming.

During my talk at saptd I also mentioned two secondary benefits: first, it’s a lot of fun to challenge yourself mentally and to try to grasp a very different approach to software development. Secondly, having more tools (languages are basically programmer tools just like IDEs etc) at your disposal will make you a better developer. Related to this is the book Exercises in Programming Style by Crista Lopez, which I’ve referred to before. Another interesting reference I alluded to during my talk is Paul Graham‘s essay Beating the Averages. Definitely worth a read!

How?

It’s of course impossible to capture a live demo in a blog post. So I won’t even try 🙂 . The list of topics that I wanted to cover was as follows:

Screen Shot 2015-11-21 at 15.14.00 .png

I managed to get to (and through) recursion, but as you can see I had to leave some important stuff out, especially the algebraic datatypes and pattern matching. So one of my lessons learned is: no live coding next time, as it proved to be too time-consuming.

By the way, before anybody points out that type inference has nothing to do with functional programming: yes, that’s basically true, but in practice sophisticated type inference is happening mostly in languages that support and embrace the functional style of programming.

As I’ve said above in the introduction, much has already been written on all of these subjects, and there are a lot of tutorials online. What has worked for me so far was doing a couple of MOOCs on functional programming. Here are some links:

Functional Programming Principles in Scala, Coursera

Programming Languages, Coursera

Introduction to Functional Programming, edX

More free online materials on functional programming:

Haskell tutorials

Clojure Tutorials

Erlang course

… or just Google for <insert favorite functional programming language> + “tutorial”.

N.B. I prefer the MOOCs to the online tutorials, because the tutorials tend to focus more on syntax, while the MOOCs really try to teach you a new way of thinking.

Last tip: Alvaro Tejada Galindo has written a number of blog posts on SCN about specific and sometimes weird languages. Among them some functional ones (Erlang, Racket come to mind). Check them out!

What’s next?

Well, as Erik Meijer (instructor of the FP101x edX course mentioned above, and a crazy guy 🙂 ) would say: Happy Hacking!!

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Christopher Solomon

    I do enjoy checking out functional programming from time to time just as a “brain workout” for myself (gotta build that muscle! haha)….but in the SAP world, I just cant’ connect the dots and find a place for it. Functional programming just seems a lot more hardware dependent than imperative programming….and by the time functional programming catches on and I have dove headfirst into it, I fear that quantum computing will be a reality and make all of it worthless anyways. haha 😛

    (0) 
    1. Fred Verheul Post author

      Hi Chris,

      I’ve the same ‘problem’: it’s hard to find a good place in SAP to use FP and benefit from it. Though IoT and Big Data scenarios should provide a starting point IMO.

      Not so worried about quantum computing 🙂 .

      Not sure what you mean by hardware dependence?! If anything it looks to me as if you’re on a higher level of abstraction, not lower. Unless you’re talking IDEs and deployments. But then Cloudfoundry support (coming to saphcp next year) should have you covered.

      Keep building that muscle! 😎

      (0) 
  2. Alvaro Tejada Galindo

    Fred:

    Great post! Everybody should be aware of the power of Functional Language 😀 And BTW…thanks for including me 😉

    When I learned Erlang, Haskell, OCaml and so on…I realized that FP is more than just a weird way to look at problems…it gives you solutions that can really scale and work without problems…it changes completely your way of thinking…

    Of course…if you ask me…Stack-Based and Logical programming should be taken into account as well 😛 But I’m just a programming junkie 😉

    Greetings,

    Blag.

    Development Culture.

    (0) 
    1. Fred Verheul Post author

      Yeah, I realize there’s much more interesting stuff waiting to be picked up.

      But lately I’ve been finding out one thing at a time works best for me.

      So Prolog, you’ll have to wait!

      You’ve set a great example here on SCN with all your different ‘exploratory’ posts, and showing that a language is just a tool, and can be used whenever the developer feels like it, or has a use case for it. I wish all ABAP-developers got that memo, but I’m not optimistic.

      Love that: “Development Culture”!! 😎

      (0) 
      1. Alvaro Tejada Galindo

        Thanks 🙂 I’m just obsessed with programming…and usually tend to go overboard with the languages that I learn 😛

        BTW…Prolog can wait as I have found that Mercury is easier and nicer 😉 It’s both Logical and Functional 😀

        ABAP-developers will get the memo eventually if people like you, Chris and DJ keep on doing the right thing 😉 You guys motivate me to keep going, learning and exploring! 😀

        “Development Culture” is the name of my team…and sure I love that too 😉 The perfect group name for me…

        Greetings,

        Blag.

        Development Culture.

        (0) 

Leave a Reply