Will Gerry might look the part of a fourth-generation farmer — dirty denim jeans, shirt sleeves rolled up and a gray beard that wraps from brim to brim on his leather hat. But once Gerry whips the smartphone out of his pocket, he starts rattling off tech jargon and analyzing data points across his farm…
It has been couple of years since I have been hearing about Functional Programming. Finally I could find some time to delve into the topic to understand what the fuss is all about! To my surprise, I found it quite interesting and a totally different thought process. It differs a lot from the conventional way we have learnt programming, which is Von Neumann style. Functional Programming brings all together another perspective to the table.
As I searched more about the same, I came across loads of material which explains the idea.
The following write up is an attempt to put together all the information I have obtained and researched. It includes material from various sources, direct links and also my personal take as I traversed through the concept of Functional Programming. The aim is to enable to aggregate the know how at one place in order to help a beginner like me to understand the background and concept of Functional Programming without meandering around for various resources. I hope it achieves the goal. Being a novice in this programming style, I might have some mistakes however the I am open to any corrections as one might perceive while reading the following.
Having said that lets start the exciting journey…..
Though it may seem like the whole idea (of Functional Programming) has picked up not long before , I must state that it has been in existence decades before. Way back in 1977 it was argued can programming be liberated from the Von Neumann style ?
What is a Von Neumann architecture ?
Earlier computers were fed programs and data for processing while they were running. Von Neumann came up with the idea behind the stored program computer, our standard model, which is also known as the von Neumann architecture. In the von Neumann architecture, programs and data are held in memory; the processor and memory are separate and data moves between the two.
In simple terms a Von Neumann computer has three parts: a central processing unit (or CPU), a store (memory), and a bus that can transmit a single word between the CPU and the store (and send an address to the store). Von Neumann languages have imperative statements — requests to the CPU to make some change to the store, and expressions (conceptually simpler) to denote values that need to be calculated by the CPU.
The following pictures tell it in a simple way..
Many Von Neumann inspired languages allow the processing of expressions to include side-effects that change the contents of the store during expression evaluation. The main difficulty with imperative statements and side effects is that they do not commute: we cannot change their order without changing the meaning of our program.
Although the above architecture was able to solve many typical problems faces during 1950s, later on it suffered an inherent limitation called the Von Neumann bottleneck.
In recent years, as the processor speeds have increased significantly the memory improvements, on the other hand, have mostly been in density – the ability to store more data in less space – rather than transfer rates. As a result, the processor has to spend an increasing amount of time idle, waiting for data to be fetched from memory. Irrespective of how fast a given processor can work, in effect it is limited to the rate of transfer allowed by the bottleneck. Faster the processor, more the time it spends idling.
There have been certain workarounds proposed and used such as Caching, Multi-threading etc. However none of them are seen to be addressing the bottleneck problems entirely. The von Neumann bottleneck has often been considered a problem that can only be overcome through significant changes to computer or processor architectures.
There are alternatives like Harvard Architecture – which has separate data and instruction busses, allowing transfers to be performed simultaneously on both busses. They are ubiquitously used in small scale machines powered by for ex. ARM processors.
However there is another set of languages called as purely functional, also called “applicative”, programming languages which try to address the above side effects and restore commutativity and preserve the rules of mathematics so that proofs concerning the correctness of functional programs are easier to establish.
What is Functional Programming ?
The functional programming as explained by Wikipedia,
In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.
The Functional Programming is a programming paradigm which deals with breaking down problems into smaller manageable functions each doing a clearly defined task without changing any state or behaviour of the system under consideration. Functions behave the same way when similar input is fed each time. Actually this paradigm derives its roots from the world of Lambda Calculus.
The case of Functional Programming (FP) is growing even stronger every other day with necessity of extreme parallelization and the fact that traditional imperative languages are finally hitting the Amdahl’s Law.
Where can I find more about Functional Programming ?
An insight into the realm of Functional Programming stresses the same further
Now the question arises why Functional Programming ?
The answer lies in the text written at DrDobbs. The two important question from the same I have listed below.
What Problem Spaces are Naturally Addressed by Functional Programming? – courtesy DrDobbs
Growing up, I’d occasionally help my dad fix things around the house, paint, etc., and from the many things he taught me, “the right tool for the job” stands out clearly. When faced with a problem, you need to consider what you have in your “toolbox” and decide the best way to solve it. Certain problems can be solved easily with a hammer, whereas with others you need a saw. You need to apply the same thought process to choosing programming paradigms and the languages that support them.
Functional programming is appropriate for applications that exhibit one or more of the following characteristics: require significant computation (compute-bound) as they can be parallelized easily, are themselves parallel in nature, can benefit from asynchronous calls, need to be provable, or require sophisticated pattern matching. This means that functional programs are not generally applicable to typical line-of-business applications that deal with objects and their state over time; however, there may be portions of those programs, e.g., portfolio basket optimization for fixed-income securities, that would benefit greatly from using functionally-based libraries. We typically see functional programming applied to image processing, machine algebra, lexing and parsing, artificial intelligence, and data mining.
Why Should I Care About Functional Programming? – courtesy DrDobbs
While you can develop concurrent, scalable and asynchronous software without embracing functional programming, it’s simpler, safer, and easier to use the right tool for the job. Functional programming enables you to take advantage of multi-core systems, develop robust concurrent algorithms, parallelize compute-intensive algorithms, and to readily leverage the growing number of cloud computing platforms.
In addition, if you’ve not already explored non-imperative programming, it’s a great way to expand your problem solving skills and your horizons. The new concepts that you’ll learn will help you to look at many problems from a different perspective and will help you to become a better and more insightful OO programmer.
What are the most popular Functional Programming Languages ?
To name a few
However this best answered in thread discussion at quora.
Which commercial entities are using FP for mainstream businesses ?
One could answer this question fairly quickly by looking at the various case studies available. For instance, on Typesafe’s Case Studies & Stories page are listed:
Nevertheless following are the few well-known companies using functional languages
- Gilt Groupe
But then how are the languages classified ?
Do you think it was interesting and another point of view could be even better ?
I have found an old but nice introduction to functional programming. Read on…
The above text was enough to trigger the curiosity bug and you want to learn Functional Programming ?
Here is very good course arranged by Coursera – Functional Programming Principles in Scala hosted by non other than Martin Odersky himself (designer of the Scala Language).
Lastly, having said a lot about Functional Programming, one might think are there any drawbacks of the same ?
Bingo !! So you thought about it !!!
Every thing comes with its own set of advantages and disadvantages and so does Functional Programming style as well.
Well, as one might think following could be listed as shortcomings
- Steep learning curve – since one has to unlearn few imperative things to embrace this new style, it is not always easy
- Too many allocations – since mutation are not allowed, a program might end up in allocating lots of objects, and then has to rely on other entities for ex. garbage collectors for the cleanup
- Convoluted simple tasks – Sometimes a simple task like reading and modifying a file content can get messy owing to avoiding of mutations
- Data Structures – There are certain data structures / algorithms designed to work in imperative way which are then difficult to include in functional programming
- Efficiency – I better not comment on it at the moment, as there experiments going on and one can find lots of discussions for and against the same. For ex. follow here… Its best left to the use case it has been deployed
- Laziness – It
- Performance – M
Few days before I had published a blog on cancer which tried stress the fact about increasing number of cancer deaths attributed to unhealthy way of living and food habits. I really felt something somewhere is going wrong.
Any self sustained and well functioning machine or a system has three basic characteristics
A product is considered good enough and well designed, only if it can withstand the test of time against unwelcome circumstances. The thing which ensures above characteristics can be termed as a Shield which keeps things in order. Further it’s our job to take care of this defense mechanism in order to keep the system functioning for longer time.
The same is true with human body as well. If one sees human body as a system it has all the inbuilt characteristics that makes it reliable, available and robust enough to deal with unwelcome circumstances. The shield which ensures the same is nothing but our immune system. To keep thebody functioning normally for a longer duration we just need give the immune system what it needs. Any damage caused to the same will weaken the defense and ultimately crumble the whole machinery.
The blog I wrote then was more driven by emotion owing to the loss of a near dear one but the now I feel the arguments I had put then were/are more or less commensurate with what “Gerson therapy” states. It has something to do with our overall way of treating our body that makes it sick.
An input to a system can very well determine the output or side effects we get.
I got driven toward his work and therapy after reading this article – so full credits to that. It just says that in order to gain a healthy living one doesn’t need artificial things. However everything is available with Mother Nature. Just pick up the right things in right combination and that is what your body needs.
As a disclaimer I must say that I’m not a promoter of therapy in itself as I haven’t experienced or practiced it. However the arguments put in this video to me seem to be logical and cannot be ignored completely.
The overall pharma industry which produces drugs for “so called” incurable diesases make million of profits each year. I don’t say they block or fool the customers as I don’t have any direct evidence but the point is when one can spend thousands once the disease appears why not try to prevent it in first place. So even if one is not convinced completely about the overall theory of Mr. Gerson, I just feel including few things like juices in our regular diet might have long lasting benefits. He is not suggesting something out of place, a little consideration might help you secure your future.
Lastly I was really caught by the following punchonline on his website without which I cannot end this write up…
Let the food be the medicine and medicine be the food.
Microsoft’s HoloLens is no joke. We’ve now tried the company’s latest revision of its unreleased augmented reality headset and even built an app for it. The new hardware, which Microsoft also showcased during its Build developer conference keynote yesterday, feels very solid and the user experience (mostly) delivers on the company’s promises. Read More
Its a very well known fact that the indian cuisine is at times complicated and time consuming. Westerners typically associate the Indian dishes with attributes such spicy with calorific value etc.
Neverthless the cuisine is unique in itself and carries a specific taste or flavor of its own which is much different than fellow Asian cuisines which use spices as well. Considering the number of ingredients put into the same, and the expertise required to mix them in the right amount at the right time while cooking brings a price. This special is one of the reasons why dishes tend to be costlier.
The following post describes a study done by Indian Institute of Jodhpur on Indian cuisine where in they have tried to put up a mathematical explanation of unique taste associated with the Indian cuisine.
I detested any form of exercise since my childhood. As I a child I had been an avid follower of sports and played a few of them including Cricket, Badminton, Volleyball to name a few. However when it came to standalone exercises I always managed to find an excuse to avoid the same. This attitude did continue as I grew up and as a result of this lackadiasical attitude I had put on some weight as I got into a sedentary job. Like every other honest soul I made several new year resolutions to change the same – but later I accepted that these resolutions are kind of shortcomings one has to accept and live with. It wasn’t like I never tried to do something. I did make few other tries – to register myself ever year for a 5.6 KM marathon only to take the free runners T-Shirt because I never really ran in the event. I have no qualms in accepting that though I was ashamed a bit every time I wore the same.
Then came the month of June 2014 and something changed then. Suddenly my inner self woke up to the fact something is not right and I got to do something about it. I allowed myself to give it a try this time by going one level higher. Apart from registration I decided to run a few 100 metres daily to see if I can cope up and observe my capacity.
2nd June 2014
I still remember the date it was 2nd June 2014 – I tried my first run. One lap in the par nearby was around 1.5 kms. I ran the first lap with lots of motivation only to feel exhausted at the end of the lap. But then I looked up my timings. I had taken around 6.2 minutes to run the 1st kilometre. The first thought was “not bad, huh”. Lets try another one to see if I can manage. Then I finished the half of the second lap with full adrenaline only to stroll in the second half. Somehow I managed to finish that lap as well. The time showed 3 kms in 20.41 minutes. By then I had enough of it and decided to take the next exit towards home. However on the way back I thought rather than walking why not just run but at a lesser speed. I did that and the result was 4.94 kms in 36 minutes. It was an incredible result considering the first day.
On that day before sleeping I thought to myself, was there some kind of a miracle today ? Or really I am fit enough to cover that much distance on the first day. However the paining legs were telling an entirely different story.
3rd June 2014
The next day morning still I couldn’t get over it (had still paining legs though :-)). I went to office that day and whilst coming back I thought of giving it an another try just to confirm if that was just not by fluke. This time I could not have allowed myself to settle for anything less than what I did yesterday. But then I was scared not to injure myself. Hence I decided to go for a couple of laps again. This time 2 laps took around 20:34 minutes (1 lap = 1.5 kms approx.) It was the time to take the exit route once again. But somehow I pushed myself to go for a 3rd one thinking that if I don’t feel like going I will abort. I had already achieved my target of 2 laps and anything above that was going to be a bonus. At the end it was 5.06 kms in approximately the same time as yesterday 36:10 minutes. It confirmed that it was not a fluke but there is some truth in it.
Every alternate day
That day I thought lets try the same for another week and run every alternate day. This was at least to keep the motivation going until the Marathon day. Then every alternate day I would test myself to see if I can manage same/better than the previous day.
11th June 2014
This was marathon day – and a weeks’ practice had bore some results wherein I ran 5.6 kms in 37:06 minutes. I still remember how delighted I was as I had never imagined myself a couple of weeks before running even a kilometre.
The assessment day
After a couple days of getting over the feeling of super achievement it was back to reality. Still the puzzle how could I do it remained unresolved. I had to understand this. I had continue this practise as well – this time as I was afraid of going back to my old habits. That day I completed my 3 laps as usual but rather than going home I pushed myself for another one. I had decided to take the exit route after that. The 4th lap was really tiring however I kept going thinking that it was the last one and anyhow that’s my bonus lap. As I came near the exit point I decided to go for some more distance and take another exit. So I ran another half kilometre. Again as I neared the other exit, I thought why not to complete this one as well, anyhow I had achieved my target for the day – hence the 5th lap. At the end I was really exhausted and didn’t have the energy to walk home. So I decided to lie on the green portion of the park around half a kilmotere away. By the time I reached there I had covered around 8 kms. in approximately 55 minutes.
The self realisation
While lying down there as I looked up in the sky I thought – “Wow that was something !!” A couple of minutes later I realised that my most productive time was after the 3rd lap. First 3 laps were obligatory for me and later on everything was a bonus. Vola !! I had resolved the entire puzzle !! I realised that all the laps I ran after the 3rd one – I was thinking of them as Bonus Laps. So there wasn’t really any pressure or obligation on me to finish something. I had a small target to start with (of 3 laps) and once that was reached, I had further smaller targets each time – 1 more lap each time. This way essentially (and unknowingly) I had broken down a large work of running 8 kms into smaller chunks which I could digest at a time. I understood that as a result I was never overwhelmed by the bigger milestone and took a sense of accomplishment at every smaller step towards it.
Hence in the end it was not really a miracle or something to do about physical capacity but it was more of a mental tenacity. It was all about how long I can stretch myself before I hit a mental block.
Isn’t it analogous to a real life scenario wherein break and make approach works? That day I learnt a lesson of life – The Key is to remove the Mental Blockage before physically attempting something deemed as un-attainable. Using the same logic until now, I have been able to motivate myself to keep continuing my runs (even in inclement weather). And I am proud to mention that within first 6 months I could hit 10 kms consistently.
I still thank myself for having the (Bonus ;-) ) thought on that day to go for a Bonus Lap – as it completely changed my perspective to look at things, typically considered as unachievable.
In real sense I had run my first RUN of life.
After all – Its All Mind Game – isn’t it ?
Last week I heard the news about one of my acquaintances passed away owing to cancer. It was always on the cards , but was just a matter of time that the inevitable occurred. The family did whatever they could, however considering their limited resources – it turned out to be not enough wherein they could avoid the eventuality. Everyone more or less knew what’s in store for them, still they were hoping against the hope for a miracle to happen and in the process exhausted their valuable economic resources which could affect their very survival in future. I was very sad to hear that.
It got me into a thinking process and realization that inspite of large technological advances we have made, there are still many areas to conquer. We live as if we are never going to die and suddenly we come to about know the worse. And this is not the only instance, in recent times I have come across such news a lot and it is really quite disturbing. I am not writing this to scare someone out, but it is more about a reflection of the thought process I got into after the very incident.
The questions like,
- What is cancer?
- Why cancer occurs ?
- Are there any specific reasons for the same?
- Can we then avoid it somehow ?
start hammering with each such news I hear.
Okay I’m not an expert into this field but it’s a layman’s point of view and I’m sure everyone must have gone through the same at some point in time.
In general terms Cancer is not a disease caused by an external agent living/ non-living. In simplest terms it is something to do about malfunctioning of cell maintenance system wherein cells simply multiply without any inhibition. It can be likened to a Computer System wherein a corrupted/affected file spreads throughout the system ultimately bringing it down.
There are many causes put forward for the same like,
- Exposure to certain chemicals
- Unhealthy diet
- May be Alcohol
- and last but not the least Heredity
However these are just the possibilities and no one can concretely say a particular reason. Cancer has been known to human beings since 1600 B.C. where Egyptian and Greek civilisations have reported such incidents. So this is something which is not new to us, but alarming rise into the deaths reported during the later part of 20th century raises a question
“What have we done wrong ?”
A logical thinking says, since as mentioned above its a malfunctioning and not a disease per say, the malfunction is generally caused by excessive use/misuse of “something”. Now what’s that “something” is a question.
The Earth in itself is a balanced ecosystem and we all are parts of the same. Every other entity keeps it in a balanced state which is quite critical. However in the past century,
- Heavy industrialisation
- Radioactive waste
- Rampant Urbanisation and removal of greenery to acquire land
- Unhealthy foods habits like canned foods and usage of preservatives
- Unhealthy life and work styles
all in my opinion have contributed some or the other way to unbalance the same. We have accepted many things which are not so natural like food habits as mentioned above which might have caused a disturbance leading into problems. Too much canned food and use of preservatives aren’t contributing to our healthy well-being. The sedentary lifestyles and resulting obesities have come into existence. Why are we making it difficult for ourselves ?
On the top of that Cancer is not a single ailment which can be easily cured by a specific medicine. It is known to be a collection of varieties of such ailments. There are as many as 100 different cancers that can affect human beings and can occur right from Brain to Groin area. Hence it is very difficult to find out a one solution that fits all.
Having said that the picture is not as bad as it looks now. There are techniques like,
- Alternative medicine etc.
available to cure the same. Still early detection holds the key and removal of the problem part is an assumed solution. The survival cases of acclaimed silver screen stars Robert DeNiro, Sheryl Crow, cyclist Lance Armstrong, cricketer Yuvraj Singh do provide a hope that we can beat it.
The following statistics from SEER also show that though we have managed to better the survival rate, the number of new cases reported have increased as well.
|5-Year Relative Survival||48.7%||49.1%||52.5%||57.7%||61.0%||64.0%||67.3%||68.5%|
We lose many precious souls on this planet every other year. Though there is lot of research going in this area and scientists are trying since years to fix the same – the knowledge and the requisite awareness hasn’t still reached the thousands affected. The treatment and the cure in itself is not easily available and is very expensive.
Though there are organisations and NGOs working in this area – we as in a system have still failed to co-operate and deliver the results by making it easily available to the needy. Specially Governments in the developing world haven’t done enough – these treatments should be heavily subsidised and there should be a pool of money to assist the affected. Special advisory cells should be setup who should act as a trouble shooting guides and providing right kind of guidance. This is one of areas where probably NGOs should come forward and advertise themselves. A better co-operation and transfer of knowledge between developed and developing/under-developed world is finally going to help us, The Human Beings.
In the end, it leaves me deeply saddened to see that,
a happily living lower middle class family, by the time come to a realisation that one of their members is affected by Cancer, its too late wherein they can do something about it – either due to the lack of knowledge and/or requisite resources – finally succumb to the ailment.