Friday, October 18, 2013

Learning functional programming at Coursera

I am currently taking Martin Odersky's course Functional Programming Principles in Scala on Coursera. This is my first time taking a course from Coursera. At the same time I signed up for this course, I also signed up for a course on Reactive Programming that Odersky will be teaching with Erik Meijer and Roland Kuhn beginning November 4.

There are hundreds of courses available on all sorts of subjects like humanities, science, engineering, and of course computer science, and all are free. In addition to the Scala course, I have started taking a machine learning course. Its format is the same as the Scala course, so I am going to assume the format is standard. (The machine learning course was the class that launched Coursera, which is another reason to think it is the standard.)

Each week new video lectures are posted. Lectures are typically 10 to 15 minutes long, and the total amount of material each week is 1.5 to 2 hours. There has been a programming assignment each of the first 4 weeks. An extra week was provided for the 4th assignment, and after watching the week 5 lectures, it was clear that the assignment covered material from both weeks.

After completing each assignment, it is submitted by using a 'submit' command in Scala's Simple Build Tool. After a couple of minutes, you can go to the assignment page on the course website and see your grade. 80% of each grade comes from passing automated tests, and 20% comes from a style checker, which will take points for using mutable state or nulls. You can submit each assignment up to 5 times with only the highest score being counted. (After that you can continue to submit the assignment, and you will receive the same feedback on your work, but you will not get credit for it.) You need to achieve an average of 70% on the homework to receive a certificate of completion for the course.

I really enjoy the format of the lectures. Some of the time Odersky is talking in front of the camera, but most of the time there are slides up on the screen. He is able to write on the slide. The translucent image of his head as he leans over a slide, or his hand and pen as he writes is a really minor feature that somehow makes the video more interesting to watch. From time to time, the video is paused while a question appears on the screen. Some questions are multiple choice and you submit an answer before moving on. Others are open ended (how would you right a function that…) and you are left to try it on your own, but there is nothing to submit before you hit continue. Odersky then proceeds to provide a complete explanation of the solution.

The quality of the teaching is excellent. The course builds a foundation by teaching the substitution method of function evaluation (which if I had learned before, I have forgotten it), then moves on to recursion, higher order functions and currying. Because Scala is a hybrid functional/object oriented language, there has also been a lot of discussion of object hierarchies and Scala's type system. Pattern matching, tuples and lists have also been covered.

I have found all of the assignments to be challenging. The format is great. You download a zip file that contains a skeleton for the solution and a series of test cases. The tests don't cover the whole assignment but they provide a good start, and give guidance on how to write additional tests. The first week I spent a lot of time, because I decided to read Scala for the impatient until I knew enough syntax to solve the problem. (It would have been faster if lists had been covered before chapter 13). After that, I would estimate that I have spent 6 or 7 hours per week on the assignments.

I believe that I am learning the material better through the course than I would reading a book. I have a tendency when reading a book to skim parts that don't interest me as much, or somehow I think aren't relevant to things I am likely to do. Also, the graded homework mean that I have to stick to a problem until I get it right, rather than until I think I know what I am doing.

I did have a little apprehension at first because the course assumes that you are going to be working with Eclipse, which I have just never really gotten the feel for. I remembered setting up Scala, SBT and Eclipse to be challenging. The course provided clear written instructions and video instructions for installing all of the necessary tools, with all of the appropriate download links.

The workload is not trivial, but I highly recommend taking classes at Coursera. The teaching is excellent. The variety of courses is amazing. I am very grateful to them for making such wonderful resources available for free.