5/20/2009

Small Taste of Scala

I just got a small taste of the power of Scala, and it was quite yummy.

It all started when I was looking for a way to convert a Java time stored in a database table into a readable date and time.  If I were to write a Java class, it would involve:

  • Create a Java source file to declare my class
    • Declare import for java.util.Calendar
    • Define a main function
      • Parse the arguments
      • Get a Calendar instance
      • Set the time on the Calendar instance
      • Print out the Date represented by the Calendar
  • Compile the Java source file
  • Run the main function on the class, passing in the appropriate argument

This seemed really time consuming and ridiculous considering how simple it should be to do this.  I’ve been spending alot of time in Python, and I would probably be able to do this from the Python REPL in a few (or 1) line of code.  So, I started looking at dynamic languages on top of the JVM.

I decided to give Scala a shot.  Scala has a REPL that comes with the SDK.  So, I downloaded it and fired it up.  I then had to figure out how to write my code.

I’ll be honest – I didn’t read the manual and as a result, I don’t know much about Scala.  I just wanted to do something really simple.  So, I noticed on the Scala site that “Code Examples” was one of the main navigation options.  I looked at the Simple Examples and figured out how to call Java classes.  Looked pretty simple.

I fired up Scala’s REPL, and defined a function:

def convertTime(time: Long) {    val cal = java.util.Calendar.getInstance()    cal.setTimeInMillis(time)    println(cal.getTime())}


The function is pretty simple.  It just takes a Long time in milliseconds and prints out the corresponding String representation of that time value.  Once this was defined, I could call the function with the values from my database table and figure out what Date value they represented:



scala> convertTime(1242942308240L)Thu May 21 16:45:08 CDT 2009


The entire sequence of events from start to finish probably took 10 minutes.  Yes – that’s much longer than if I had written a simple Java class.  However, I think it’s VERY impressive to go from 0 to Scala function with results in 10 minutes.  To me, this is a a testament to how approachable Scala is as a language.  Further, I am amazed at what a great job its implementers have done with creating a very “dynamic language” experience on top of the JVM. 



Now, if I only had more time to play with it…





































1/23/2009

Traveling in One Bag

Over the years I've started realizing some things about myself. One of which is that I'm always going to be looking for the way to do something better. This has, and will, lead me to drink the Kool Aid of productivity experts and organizational systems. I admit it - I'm a productivity geek.

About a year ago I stumbled upon the One Bag site. It obviously struck a cord with me and I hungrily devoured every page on the site. I decided right then and there that I would buy a suitable bag, lighten my load, and make the jump on my next trip. This would be just the thing I was looking for on business travel.

The bag I chose was a Red Oxx Air Boss. This was largely based on the fact that Doug Dyment, the creator of One Bag, helped design it. However, I was drawn to how well designed and built the bag appeared to me (I also have a thing for bags). Once I received the bag, I realized that I had made an exceptional choice. The Air Boss is simply fantastic. I won't go into it here, because others have lauded it at length.

My first excursion traveling in one bag was a 5 day vacation to Tennessee. I packed my Air Boss using Doug's bundle wrapping technique for my clothes. I took a few pairs of jeans which made my bundles big and heavy, but everything fit in the Boss. I also packed enough shirts, undergarments, toiletries, laptop computer and charger, a book, and a magazine. I packed a dressy pair of shoes in my wife's bag (she was checking hers), but everything else fit in one bag! The trip was great - didn't have to worry about lost luggage, didn't have to worry about weight limits, and I didn't have anything stowed under the seat in front of me. A successful trip and I was happy. But, could I make it work for business?

This week I had a 3 day business trip to Chicago. I only needed to pack 2 days of clothing because I traveled in 1 day and out the 3rd day. I packed up the Boss with 2 sets of clothes, pajamas (not necessary, but I had a room), undergarments, toiletries, laptop and charger, Jawbone, USB sticks, iPod, Headphones, Kindle, small notebook with pen, plastic folder, a magazine, and USB charger cords for iPod, cell phone, and Jawbone. I wore my heavy coat with my gloves and ear muffs in my pockets. I packed my laptop in a Brain Cell from Tom Bihn. This makes a great little laptop bag when you get to your destination, and you can use the shoulder strap from the Air Boss with the Brain Cell.

Traveling light to Chicago on business in the winter was a breeze. My Boss easily fit in the overhead on the plane. I folded my coat and put it under the seat in front of me. The Kindle was excellent because I took two books, a whitepaper, and an essay with me on the device drastically cutting down on my load.

I have now become such a huge fan of traveling in One Bag and my Air Boss, I don't want to go back. Although I'm still not sure I fully understand how people travel internationally this way, I'm building the courage to try it some day. I'm a convert... and a geek... especially because I took the time to write this post! ;-)

1/04/2009

Twisted Documentation: The Pasta Theory of Design

1405309321_63eddae70d_b Over the holidays I’ve been learning the Twisted framework and reading through the Twisted Core Documentation.  I came across this gem of an analogy…

The pasta theory of design:

  • Spaghetti: each piece of code interacts with every other piece of code [can be implemented with GOTO, functions, objects]
  • Lasagna: code has carefully designed layers. Each layer is, in theory independent. However low-level layers usually cannot be used easily, and high-level layers depend on low-level layers.
  • Ravioli: each part of the code is useful by itself. There is a thin layer of interfaces between various parts [the sauce]. Each part can be usefully be used elsewhere.
  • ...but sometimes, the user just wants to order "Ravioli", so one coarse-grain easily definable layer of abstraction on top of it all can be useful.

Twisted Documentation: The Evolution of Finger: making a finger library

I love it!

10/31/2008

Alfresco Developer Guide

imageMy friend Jeff Potts announced today that his book, “Alfresco Developer Guide”, has been released.   Jeff’s been working on the book for quite a while, and it looks to be packed with great examples and information about the ins and outs of the Alfresco content management system.

I’ve ordered my copy.

10/21/2008

The Weekly Squeak: ‘Smalltalk is cool again’, says Gartner

Via: The Weekly Squeak: ‘Smalltalk is cool again’, says Gartner

There is an article from a Gartner analyst talking about a renewed interest in Smalltalk.  Speaking for myself, I’ve come around to Smalltalk over the last couple of years and I’m very glad that I did.  It’s one of the coolest languages/platforms I’ve ever laid my hands on.

In fact, in case you were wondering, I’ve temporarily put Erlang aside to go back and visit Smalltalk land.  It’s just much more productive when you have limited time available.

7/30/2008

Finished the Erlang Book

I finished reading Joe Armstrong’s “Programming Erlang” book a couple of nights ago. It’s a great introduction to Erlang as well as a great programming book. I’ve always loved the Pragmatic Programmer books, and this one is no exception. It’s filled with non-trivial working examples and pointers to more information. It left me feeling ready to dive into the Erlang docs and write some code!

So, that’s exactly what I’m going to do. I’m currently plotting a program that I’m going to write in Erlang. I want to make sure that it’s non-trivial and that it benefits from concurrency. I’ll loop you in when my scheme is ready to hatch.

Erlang Podcast with Joe Armstrong

I just listened to a good podcast interview with Joe Armstrong on Software Engineering Radio. Joe talks about the history of Erlang, its features, how the VM is implemented, and how you can use it to scale on multi-cores or across multiple machines. It’s a good introduction to what Erlang is from the man himself.

7/26/2008

Erlang Update

I’ve been tearing through Joe Armstrong’s book “Programming Erlang”.  I started reading it about 14 days ago, and I’m already in Chapter 17.  It’s a well written book and a great introduction to the language and some key libraries.

I think the reason I’m working through it at such a rapid clip is that Erlang has captured my imagination.  I’m fascinated by how easy it is to program multi-process applications and distribute those processes across machines.  I’ve written multi-threaded code in Java, Python, and Common Lisp.  Erlang is BY FAR the easiest language for writing MP code.

I can’t wait to finish the book and write my own application. I’m forcing myself to finish the book first because I want to make sure I know all the right tricks before I get started. I think that’s the right idea because I’m now learning about Mnesia and soon I will learn about advanced OTP techniques.

I can’t convey how excited I am by this language/platform. I saw my friend Jeff last night and I bored him to death as I gushed about Erlang. He mentioned that he had recently posted about CouchDB and that it would be cool to develop something social on top of that. Indeed…