Monday, November 19, 2012

Another Look at Play2

Matt Raible has some good writeups on Play2.  We switched to Scala about a year ago.  For lab week, a few of us evaluated Play earlier this year.  At the time I mostly worked with the persistence layer, anorm.  Our conclusion was that it wasn't quite ready for what we wanted to do.

Just recently I finished a lab week and decided to take another look at Play.  Here are some conclusions.


Overall
The big question is, compared to what.  At work we use Grails on the web side and Scala on the back-end.  The reality is that we leverage front-end engineers to help us make Time Warner Cable web sites look and behave well.  In our situation I don't think I can recommend it.  But if you're in a hardcore Scala shop and your Scala engineers can do enough of the front-end work then Play might be a good option.

Working with routes and templates felt a lot like Android development.  You work in a non-code DSL to create your routes and that turns into code that you write against.  Same for templates, they just turn into functions.  sbt run fires up their own netty server, it's solid.  It does a great job picking up changes. I didn't restart the play development server for a few days and it didn't miss anything.  Play also gives you helpful error messages in the browser when there are problems.

Routes
They're handled in a text file.  I guess it's good because there's no cruft surrounding the definition of your routes.  It's bad because I think Scala is the perfect language for defining an internal DSL to handle routes.  It'd be great to have IDE support while working with routes.

Controllers
Everything feels very idiomatic to Scala.  For example optional parameters are (drum-roll) Options.  Play doesn't have you use servlet filters, you just wrap functions.  The controllers themselves are not easy to test but there are workarounds such that you can do good unit tests.

Templating
It's familiar to someone used to Scala.  Templates are just functions and have input parameters with types.  This gets statically checked and your IDE will bark at you if you send the wrong data type into a template.  I think that's awesome.  The templating is not as rich as Groovy Server Pages.  For the actual templating work there is no good IDE support.  It'd be great if TypeSafe took this on.  The templating that Play gives you would be painful for front-end engineers that are only familiar with HTML, CSS and JavaScript.

Testing
They have utilities to help with testing.  All the examples use Specs, I haven't got the Specs memo yet, still using jUnit (get off my porch).  The biggest problem is that the controllers are objects so it's hard to do good unit testing.  I found a workaround that someone suggested.  Basically your controller is a class, in this case taking a dependency via the constructor.  Then the object that you tell Play about in the routes extends that class.  This seems to work in my toy example.

object MockUp extends controllers.MockUp(new ProductionGuidCryptoServiceProvider()) {}



Friday, November 16, 2012

The Setup

One of my favorite blogs is The Setup.  They feature various people that use computers in one way or another to do their job and simply ask them what their setup is.  Well since they haven't asked me what my setup is yet (not realizing that I'm kind of a big deal) I'm going to just post this on my own.


Who are you, and what do you do?

I'm a software engineer.  I have worked mostly for telecommunications companies.

The most challenging job I had was leading up a small but capable development team responsible for routing phone calls, including geo-spatial 911 traffic.  This was at a startup without much support.

Now I'm a Senior Engineer at Time Warner Cable.  My home office is in Denver, Colorado but I work remote in Lafayette, Louisiana.  I fly back about once a month.  The team I'm on works on the services that IP devices use to get streaming television content.


What hardware do you use?

My main computer is a MacBookPro 15" from 2010.  I also have a MacPro Desktop.  Each computer has a 27" Thunderbolt Display.  I was skeptical at first but the Apple Magic Mouse is an amazing piece of equipment.  I use 1 standard keyboard for the desktop but primarily I use the bluetooth keyboard.  I wouldn't mind having the bigger size but the travel from home keys to the mouse seems like an eternity compared to the bluetooth keyboard.

I also have an iPad 2 for work.  I use it to validate software releases, cable channel updates.  I also have an Asus Transformer to do the same thing on the Android platform.  I don't write the client code but the team I'm on is responsible for many of the back end services that these devices talk to.

My phone is an LG P999 Android phone.  Works great, has all the apps I need; Evernote, Pandora, Dropbox, Google Reader.


And what software?

I run MacOS on both machines.  The laptop is 10.6, the desktop is 10.7.  I hear so much griping about upgrading the OS that I don't mind waiting a while until the kinks get worked out.  Before going to the Mac a few years ago I was strictly a Linux user.  It has been a smooth transition to the Mac.  I still feel comfortable whenever I go back to Linux.  If Apple gets too stupid I'll probably switch back.

I spend most of my time in the IDE.  I run Eclipse with the Scala-IDE plugin.  I also use a code coverage plugin for Eclipse that can handle Scala called eCobertura.

Despite having an IDE I spend a lot of my time in the console, for that I use iTerm.  Being a long-time VIM user I'm thankful for MacVim, it's a great distribution of VIM.  I use Homebrew for installing commandline tools that are missing from the Mac.  At work and in my personal development we use git exclusively.  On my desktop I run Jenkins for continuous integration.  It polls the git repository on my laptop and our remote GitHub Enterprise servers at work.  It continuously compiles our code, runs tests and generates reports.

When using a browser for development I will typically use Chrome.  The Chrome plugins I use are for either maintaining privacy or doing software development.  I use Poster, Edit this Cookie, AdBlock, Chrome Nanny, Ghostery, Time Tracker, Evernote and HTTPS Everywhere.

I use ShareMouse to make both computers and monitors feel like one big computer.  The price is right (free in my case) but it's occasionally glitchy.

For remote work these come in handy: TimeZone,  Skype and join.me for impromptu screen sharing

I use Evernote to keep track of information, DropBox to sync files, Pomodoro on occasion to focus, f.lux to save my eyes when working after dark, Alfred as an app launcher and searcher, Marked for previewing MarkDown files. MindNode to create mind maps, PandaBar to make listening to Pandora radio not depend on Adobe Air (WTF) and ShiftIt to easily organize windows.


What would be your dream setup?

Pretty much my same setup but with more RAM.  Maybe some SSDs.  The Scala compiler does a lot of work for you so you need top end hardware when you're doing any Scala project that is beyond trivial.  Although our own informal analysis at work seems to indicate that SSDs don't buy you too much for building Scala code, seems that good old fashioned RAM and processor speed is what you need..

Other than that I'd like to have a screaming ThinkPad or AlienWare laptop running some Debian Linux variant.

Friday, November 9, 2012

Functional Programming Principles in Scala: Wrap Up

So here's the deal, I was dreading the thought of doing another assignment in the Odersky Scala course on Coursera.  I have other projects I want to move on to and man I'm not built for the academic side.  Then they send out an email telling everyone the minimum number of points we need to complete the course.  Alt-tab over to a Google Doc spreadsheet, do some quick math and presto, I have way more than enough points.  So, I punted on the last assignment.  Yep, I'm that guy, I wrapped up my CS degree with a D in post-calc stats to get the diploma.  That'll work.

Besides my weak finish the course was awesome.  If you're in the Scala space and you are anything short of a wizard I don't understand why you wouldn't jump on the opportunity to get instruction from Martin Odersky himself.

The Course

The focus of the course, as you would imagine, is functional programming.  They take much inspiration from SICP.  I don't know how much of it was SICP or Martin Odersky himself but the course laid out the proper motivation and revelation of information such that my brain was willing and able to accept it.  This was a well thought out, professional course.

50,000 people signed up for the course.  I don't know how many people finished it.  The course developers created an automated system that analyzed your code to make sure it passed their own tests along with some other code analysis.  For example I had some code implemented that passed tests but it didn't use the groupBy capability in collections.  That was the point of the exercise so they dinged me.  Fair enough, they're checking lots of stuff.

Because of the automated nature, the programming assignments have to structured in a particular way.  They have to lead you down a path.  They can't just give you an assignment and a blank canvas.  I think this is okay.  But it's a different approach to programming assignments and worth recognizing.

To Those That Come After

Here are some things I recommend to someone taking the course when it is offered next.

  • Get the SICP book and refer to it, it helped a few times.  Odersky mentions it and I think it's fair game to refer to it.
  • I didn't do any of the video quizes, I don't think it hurt me.
  • Leverage the Scala-IDE worksheet, dump code in there and play, I think it's better than the REPL.
  • The forums were sometimes (not very often) helpful.
  • Submit early and often.  You get great feedback.  Some co-workers found that if you put print statements in your code you'll see the output in the online feedback, this can give you some indications of the additional test scenarios they are using to evaluate your code.

The Cheating

9 co-workers and myself have our own Skype room dedicated to the course.  No one wanted to cheat, we all wanted to get a lot out of the class.  We even made sure that no one gave away spoilers before the projects were due.  But we also knew that we would benefit greatly by looking at each others work when we were done with assignments.  I actually learned some cool stuff and it was a great time for me to accept the information since I just got done spending hours trying to solve the same problem.  So I was one of the guys that had his assignments up on github.

Then we get the email from the admins that we need to take it down.  That's all cool but they cited how we signed an agreement acknowledging we wouldn't post our stuff or whatever.  I wish you could see my face but let's just say, no one fuckin reads EULAs.  If you don't already know that, especially if you're in software I'm not sure what to say.  So I took it down from github and put it on a private repo on bitbucket.  If you don't already know, you get free private git repos from bitbucket, good stuff.

On From Here

I'm doing things out of order here but I'm going to go through the Scala Koans from here.  Just to loop back and go thru the basics some more.  In the forums the course administrators say they plan on offering additional Scala classes through Coursera.  I look forward to seeing what they offer.