Introduction to functional programming
I vaguely remember reading something about functional programming back in my engineering days. We did study Lisp and Prolog a bit, but it was done at a very abstract level. Ever since i joined the industry i have been writing object oriented code, or so i like to believe :) The point being that am completely new to this paradigm.
Functional programming languages have largely been emphasized in academics rather than in commercial software development. However lately, few functional languages have gained popularity.
- Erlang - used by Facebook for their Instant Messaging.
- OCaml - used for financial analysis
- Scheme - used for training simulation software and telescope control
Scheme (which is a dialect of Lisp) was in fact used in early macintosh computers.
What exactly is functional programming?
Its difficult to give a precise definition, but generally speaking:
In functional programming the basic method of computation is the application of functions to arguments. It also avoids state and mutable data.
Lets say, we need to compute the sum of 1st ten integers:
- In an imperative language like Java, the code would look something like this:
total =0;
for(i=1; i<=10; i++)
total = total +i;
- In a functional language like Haskell, the code would be:
sum[1..10]
Why is functional programming useful?
- The abstract nature of of functional programming leads to simpler programs.
- Supports number of new powerful ways to structure programs.
I think with this background, we should be be in a position to get started. Next post shall cover the basic concepts and principles of functional programming.
Hope this post motivates you to give functional programming a try.
Comments
Post a Comment