Monday, March 25, 2013

Scala and Functional Programming Class

In a previous job I self taught myself Scala and Actors model using Martin Odersky's book.  I haven't used it in a while, but I have been itching to learn proper idiomatic functional programming.  Scala lets you use both OO and FP principles, so it easy to revert back to Java-style OO when not pushed.  I feel like Scala is a good language to learn because it straddles that line between being a "cool" and productive language but also adult enough to scale and taken seriously by large enterprises (i.e. you can find a good job).  Moreover, its sweet spot is concurrency with actors and STM, which allows horizontal scaling over many cores and machines with minimal effort.  From what I can tell developing concurrency correctly is one of the strongest skills a programmer can have over next five years.

That is why I jumped at the opportunity to jump on a free online class taught by Odersky himself at Coursera.  Today is the first day, so sign up now if you interested in getting "credit".

Installing OS X Mountain Lion on VMWare Workstation 9

Over the weekend, I was doing some iOS programming on my Macbook Air and was getting annoyed by the small screen size and constant switching between my laptop and my desktop screens.  The obvious solution would be to buy a monitor cable to hookup my laptop to one of my monitors, but since I have been using virtualization more, I became curious if there was a way to run OS X as a guest on my more powerful Windows 7 machine.  I already have moved most of my Linux-based web programming to a headless Debian virtual machine (which works splendidly with puTTY and samba).

OS X guests are not officially supported on PC hosts such as Windows, however since Apple has since migrated to an Intel architecture, it should be theoretically possible.  A quick google search revealed that a benevolent group of hackers at the the SoulDev Team have already put together a painless solution.  Here are the steps I had to take to get this work sufficiently:

Before you try this, you need to make sure your machine is powerful enough to do virtualization.  If you bought or built the machine in the last couple of years mostly likely you are OK (my previous machine which was 8 years old could run Debian and barely Windows XP guests on VMWare Player).  You just want to make sure you have hardware-assisted vitrualization support in your motherboard.

My machine is an Intel i5-3570K (ivybridge) with 16 gigs of RAM running Windows 7 64-bit.  The souldev team posted instructions on how to get this running on an AMD architecture if that is what you have, but I believe the result is less reliable than using an intel machine.
  1. First you need to get the OS X image from thus torrent link posted on their download page (note that you should have a valid license for OS X before you do this legally speaking)
  2. When you expand the z7 file, you will see three directories.  The folder named "OS X Mountain Lion" contains the vmware image files, which we are going to use.  So, move these files to the directory where you want to store the virtual machine.  The instructions recommend that you run an "unlocker" first from the third directory which unlocks the "Mac OS X" operating system option in the VM settings, but I ended up not running it due to security concerns.  Note that I am unsure if bypassing this step will work for for every machine or I was just lucky.  It also might degrade performance slightly, but I am also unsure about this.
  3. Start up workstation and open up the vmx file.  Adjust the amount of RAM available to the guest to at least 2 GB for decent performance.  I toyed around with increasing the number of processors but didn't see much of an improvement, so I left it at 1.   After starting the VM, tell workstation that you "copied" the virtual machine from another location.  During the first bootup, it is pretty slow.  You will probably see a grey screen for a few minutes followed by the OS X "computer setup" screens.  Here, you probably want to skip over the part about setting up iCloud and registering the copy.
  4. Once it fully boots up, you probably want to install VMWare tools.  The freshest copy of the tools are at this location.   Inside the guest, download "Install VMWare" and run it.  This will install VMWare tools for your OS X guest.  After a restart, I also installed the file VMsvga2 from the same location.  This dramatically improved my graphical performance on the guest and allowed my to choose display settings that were native to my monitor.  I am sure the success of this is dependent on the machine specs you have, but I found it to be the determining factor between a neat experiment and actually usable.
At this point your guest is almost fully functional.  I was even able to upgrade to 10.8.3 using the app store (you should make a snaphot before you do this) and download XCode.  The only thing that I believe there are issues with is getting iMessage to work properly.  You can read up on it this post if that matters to you.

I hope that was helpful even though it is pretty straightforward.