Is there a functional programmer inside you?


I only just realized I have had a crush on Functional Programming for ages. When I first learned and used Generics and Anonymous Methods in .NET 2.0, I instantly fell in love. Next came C# 3.0, LINQ and XAML, and I was instantly drawn to it’s declarative nature and style. Having done programming for a relatively short time, I delved mostly in Imperative Programming in statically typed languages like C#, VB.NET and C++. C# 3.0 had a facelift by getting some aspects of functional programming (like lambda expressions) and that made it more powerful, fun and simpler to write/understand. Eventually I decided to venture into the world of Functional Programming, namely F#.

After reading my first book on F#, I was confused, lost and unimpressed. The language is great, being dynamic and all, like not having to specify types by using type inference and writing lesser code compared to imperative languages made it appealing. However there are also aspects of F# that made my brain explode, like “everything is immutable” and it looked to be only useful as a mere scripting language. So how do you write business applications?? Where’s the OO element in this? More importantly, problems I can solve using a static language has become too difficult for me in a dynamic language. My brain just can’t seem to re-program itself….I found myself handicapped…

Many moons later, I read about how Microsoft is going to introduce IronPython and IronRuby into Visual Studio 2010 as first class languages, and they will be fully integrated into the CLR. I picked up an IronPython book and re-started my journey on Functional Programming, hoping to see some light at the end of the tunnel this time around. IronPython is clean and straightforward, and so easy to pick up, but more importantly it has an OO aspect to it. You can find some of the OO structural goodness in IronPython (like classes, inheritance…etc), an interesting feature called Duck Typing (a much looser coupled version of polymorphism) and that brought me back to familiar grounds. I got excited…

Today, my excitement was heightened when I read the first free chapter of a book called “Functional Programming for the real world“, written by Tomas Petricek and Jon Skeet. Not only is it very well written, it makes a lot of sense. Even in the introductory chapter, the authors challenge you about how well you understand C# code (about passing by reference and value) to prove the point the Immutability has it’s benefits. Amongst the many examples using C# and F#, the authors attempt to show you the benefits, elegance and real world use of a language like F#, stating that imperative languages often require us state the “HOW” to get things done, whereas functional languages only require us to state the “WHAT” we want done. There was also mention of how immutability helps in writing threadsafe multi-threaded code, as well as F#’s new feature called Asynchronous Workflow which allows us to execute code in parallel, tapping into the power of multi-core processing. After reading 28 pages of the first chapter, I sat back and attempted to digest the material, pleasantly realizing that the authors have managed to twist my brain just a slight bit towards believing that there is potential in a dynamic language in solving some of the most difficult problems we face in programming. The rest of the 17 chapters look extremely interesting too, particularly chapter 15 Creating Domain Specific Languages….I’m intrigued.

I can’t help but have the impression that this book is structured and targeted at imperative-style programmers. Using C# code samples gives us something to relate to, thus easing the rough transition to a functional way of thinking. Thanks to the authors for writing a very fascinating book, and reviving my interest in functional programming. Needless to say, I bought the eBook version and hope to be even more pleasantly surprised and excited with every chapter. Til then…do check the book out.

Share this post :
Advertisements

One Response to “Is there a functional programmer inside you?”

  1. Moving to a functional state of mind « Code Blitz Says:

    […] Is there a functional programmer inside you? […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: