Friday, January 6, 2012

Learning Scala : It's easy!

Authored by Win Myo Htet

I have read some comment on SO about how they have learned a new language. One commenter said that a week is too short, yet, somehow the management expect that people learn a new language in a week. Some smart people chime in and said that how they have acquired a new language: "Java in 3 days", "C++ in one week" or "given a C++ book after the successful interview to start coding in it when the individual begins the work (the time difference between the interview date and starting date not given)", "(relevant or not about acquiring a new language) one was given some circuit board on interview". There even is a book "Seven Languages in Seven Weeks". I cannot learn seven language in seven weeks . Well, definitely I am not in a smart camp. I am an average one. There is a well developed theory and term for programmer like me, I think. Something like COTM or something.

It takes me over a month to learn Scala. I don't claim to know all now. I don't know if my lack of academic background in CS or my lack of exposure to functional programming has lengthen the time to learn Scala. Definitely, I can say that Scala is not hard. Then, it must be easy! Learning on my own (as norm in this industry), I stumbles here and there. For example, I should have at least browsed the Scala List API for available functions. There also is a balancing act between functional programming and OO paradigm. I think, that's where a lot of people stumble too. After all, the functional programming paradigm with its immutability make the imperative programmer felt being hand cuffed and they get obsessed with the restraint such that they fail to see how it is liberating them from corruption of data. Twitter has done a good job of balancing between the two. I have gone through some of their open source projects on github and analyze their usage.

Twitter usage is not very far off from imperative domain. They make use of Scala pattern matching a lot to its effect and not afraid to use mutability when it is needed. After all, Scala has given such elasticity. Talking about Scala elasticity, Lift framework, a popular Scala open source web framework, tips toward functional programming side. There is nothing wrong with both approaches. It depends upon how much one is familiar with the functional programming and how much one want to leverage the edge that functional programming give. I have also seen people writing imperative code in Scala and said "Why bother?". "Yeah, why bother?" Though I am looking toward for the day when I can use more functional programming stuff, my pragmatic side make me settled on the Twitter's approach of the mix paradigm. After all, the poor pure functional programming language has to be quite inventive to address some of the taken-for-granted-feature from imperative world. Trust me I want to learn that language too, just to be in cloud nine.

If I can travel back over a month time  to guide me, there won't be much to tell my old self except to skim through the Scala List API at least once and to have a balanced approached to functional programming and OO paradigm. Everything else I have been doing have been on a right track, like not using any IDE and taking advantage of Scala REPL, getting my hand dirty writing code with Scala,  read some blog (definitely avoid the political ones!), write some blog (it forces you to have clarity of understanding on the thing you write.) and read some codes too.

Learning Scala makes me a better programmer by being exposed to a different  paradigm and knowledge.  There is nothing much else to say. I have to admit that I have to make some conscious effort to learn Scala since I am not omniscience.

Authored by Win Myo Htet

No comments:

Post a Comment