Friday, November 9, 2012

Think Functionally - Writing program the functional way

After taking the "Functional Programming Principles in Scala" course on, my understanding and appreciation for "thinking" functionally grew a lot. One of the big benefits the course have on me is fixing my misconception on recursion. I had disliked writing recursive functions thinking it was very susceptible to stack overflow. Although this is true, the course explanation on tail call help correct my misunderstanding.

I was just browsing the IT forum on and came across a post on a university question on about writing a program to give change to for a vending machine (note it is in Chinese). Don't worry about he forum. Although there are a definitely a few good developers in there, the questions and discussion are generally of pretty low quality. I just browse occasionally hoping it will help me getting to know the IT industry in Hong Kong a little better.

I recall doing a similar problem in university for either an assignment or exam question, and I recall doing it the "Imperative way" with loops and states. It was an awful experience.
Now arm with thinking functionally, I took another crack at it and seems much easier.

Sunday, November 4, 2012

Completing the functional programming principles in Scala

I did it! Completed the final assignment #7.

I had doubts whether I had the will power to complete the course, but I am happy I did it. Not because I have to, but purely to satisfy my curiosity.

Now about Scala.

There are lots of veteran opinions on the topic of Scala:


While there are lots of merits on "issues" with Scala, it really boils down to Scala being a relative young language. I find the claim "Scala is too complex" bogus. Most things are too complex before you take your time to learn about it. Hell, programming is too complex for the average Joe without any programming background.

Scala exhibits the typical issues with a young language:
  • Tooling - such as build systems (sbt) and IDE (Scala Eclipse Plugin) have a lot to be desired.
  • Debugging - The are lot to be desired for a more sensible stack trace on error

However, just the 2 issue above is enough to justify not to use Scala in an enterprise project ... yet. This doesn't mean people should shun it though. 

Scala is one of the nature candidate to evolved into from Java, with both backward and forward interoperability with Java. Companies simply will not drop their years of investment in Java for the next shiny programming language. 

I think Scala community is on the right track though.

I believe through education, developers acceptance of  high order language will become wide spread. The productivity and efficiency provided by these higher order language will justifies the migration to it.

Hey, if not for the Scala language itself, spending time to just learning the concept of Functional Programming is a good investment.