The Setup

I started my new job at edorasware last week, with a new & shiny 15-inch MacBook Pro. A fresh computer with a blank OS is both, a blessing and a curse — it takes quite a while until it feels like home again. And even after a week, I still miss a few configuration settings or shortcuts here and there.

Setting up the new machine was certainly an opportunity to consolidate the apps and tools I like and need. Inspired by The Setup, here’s what I currently use to get things done:

As a Java developer, I spend most of my time in IntelliJ IDEA, the best IDE ever (weight this statement by the fact that I used Eclipse for 7+ years before). My second home is the command line. I use iTerm2, which has excellent search support, provides mouseless copying, and is more unixy than the official Terminal. I’m still learning to use Finder efficiently. The TotalFinder plug-in, with tab support and its Folders on Top mode, is my latest attempt at making friends.

A few crucial things help me organize & navigate my workspace: I use three virtual desktops (via Mission Control) which I access by keyboard shortcuts — 1 for Mail/Calendar, 2 for Browser, and 3 for IDEA. A launcher helps me kick-start applications. I switched from Quicksilver to Alfred — it provides the same features and is under active development. Divvy tames all window sizes & positions, clearly a missing feature in OSX.

Transitioning from Snow Leopard to Lion was more challenging than anticipated, mainly because of its different mouse usage paradigms. Most of the built-in gestures are easy to use, but some of them collide with my old habits (how the heck can I turn off horizontal scrolling in order to re-map the swipe gesture to back/forward navigation in IDEA?!). A while back I forced myself to exclusively use taps (rather than clicks) on the trackpad. Wow — the absence of the mechanical noise makes such a difference, everything suddenly feels very light and smooth!

These are pretty much the apps at the core. In addition, I like Chrome, 1Password, TextMate, Dropbox, Skype, Spotify, Acorn, Inkscape, Lightroom and OmniGraffle — just to name a few.

What are your favorite tools we should all know about?

GAE + Gson + AngularJS

I have been playing with AngularJS lately. It is a JavaScript library with the following tag line:

What HTML would have been had it been designed for web apps.

All I can say after a few hours: HTML would haven been great! It would have had a clear MVC separation, data binding, dependency-injection, and it would have kept development simple & fun.

My web app know-how is very rusty, so I hacked together a simple proof-of-concept, just to see how AngularJS actually feels. Here are the crucial snippets from my Google App Engine Java back-end (to generate JSON), and the HTML/AngularJS view (to render it).

The Servlet part:

protected void doGet(...) {
  response.setContentType("text/plain");
  String[] movies = new String[]{
    "Buffalo 66",
    "Jackie Brown",
    "Vicky Cristina Barcelona"};
  response.getWriter().print(new Gson().toJson(movies));
}

The AngularJS Controller (controller.js):

function MovieListCtrl($xhr) {
  var self = this;
  $xhr('GET', 'http://localhost:8080/json',
    function(code, response) {
      self.movies = response;
    }
  );
}

The HTML/AngularJS View (index.html):

<body ng:controller="MovieListCtrl">
  Rahel's favorite movies:
  <ul>
    <li ng:repeat="movie in movies">
      {{movie}}
    </li>
  </ul>
</body>

Check out the official AngularJS Tutorial for more details and a ton of cool examples.

Scala Gems #4: Generating Data Matrices

Generating matrix-shaped test data is easy in any spreadsheet application: Enter a few cell values and use the fill handle to complete all others. But firing up a spreadsheet somehow feels lame. This Scala three-liner can do the same:

println(Array.fill(7, 3)("X").map(
  _.mkString("\t")).mkString("\n")
)

Is it readable? No. Is it handy? Yes!

Scala Gems #3: Named Parameters

Just a quick one this time (it’s easter holiday and the weather is simply too beautiful to waste time in front of a computer). Anyway, have a look at this constructor call:

MigrosEgg(GREEN, BLUE)

Unless you’re Swiss and just know that I’m referring to the “Extra” variant, wouldn’t it be a lot less ambiguous to write

val aMigrosEgg = MigrosEgg(dotColor = GREEN, bgColor = BLUE)

As of Scala 2.8 you can name your arguments. You can also leave out those which have default values, shuffle their order — or you can simply have another one of those little suckers:

val notAMigrosEgg = aMigrosEgg.copy(dotColor = PINK)

Happy easter everyone!

Scala Gems #2: Getting Functional

As promised, here is the second post in my haphazardly thrown together Scala series. Over the past few days I have read some chapters in Odersky’s Programming in Scala, and most importantly, I have written my first ~100 lines of code (a basic Minesweeper app with a simple Swing UI). It’s been a lot of fun, and I am still very enthusiastic about many new concepts & constructs. When coding, the biggest challenge is to not fall back to imperative Java style, but really use the functional concepts wherever applicable. I am probably still not radical enough, but for the time being, here is my take on revealing non-mined cells:

def reveal = {
  if (revealed == false) {
    revealed = true
    if (adjacentMineCount == 0) {
      adjacentCells.foreach (cell => cell.reveal)
    }
  }
}

In summary: 1 usage of => (and even a recursion ;-) ).

Scala Gems: #1

This article finally did it: “Guardian.co.uk Switching from Java to Scala” — it made me jump head first into the Scala newbie pool. Of course I wanted to learn Scala for quite some time already, but I somehow never managed to get my act together.

Life as a Java programmer had gotten harder over the last few years. Not that I don’t enjoy my job anymore, to the contrary, but reading about all these highly dynamic youngsters hacking together their Python/Ruby/Groovy wizardy at the speed of light has made me feel even older than I already am. Old-fashionedness at its finest: I absolutely can’t relate to all this enthusiasm for dynamic languages. Ok, I admit that some script-fu will certainly help getting this nasty little problem solved quickly, but how the heck will a huge Rails project be maintainable over 10+ years? Or do we still have to wait longer for time to tell that it will fail? Do these people write tests for each and every thing that otherwise would be checked by a compiler? Isn’t this a rather high price for a little duck-typing?

I am obviously being cynical, but luckily I am not the only one in doubt. Some great brains also think that throwing away the type system is not the best compromise to make in order to get rid of Java’s (admittedly extensive) boilerplate. In this excellent talk, Bill Venners speaks about his preference for typed languages. He mentions “deterministic refactoring” as the main benefit, which he explains like this:

I don’t like types because I think they proof my program correct [...] but because they can proof changes that I make to my programs are correct

Coming back to Scala: It seems to combine the best of all worlds — strictly typed, functional & object-oriented, radically concise, and just close enough to the Java world for old-timers to transition gradually ;-)

To keep my new Scala heart beating, I will start posting weekly Scala gems. Let me start with the example given in the above interview — just to illustrate what “no boilerplate” and “concise” really mean:

Java:

public class HowdyClass {

    private String name;

    public HowdyClass(String name) {
        this.name = name;
    }

    public String sayHowdy() {
        return "Howdy " + name;
    }
}

and in Scala:

class HowdyClass(name: String) {
    def sayHowdy = "Howdy " + name
}

The second example is my personal highlight after roughly two hours of playing around with the interpreter: Initializing a two-dimensional grid with indexed cells:

class Cell(x: Int, y: Int)
Seq.tabulate(3, 9)(new Cell(_, _))

This is actually almost too concise (or at least as a functional noob it took me quite some time to understand it). Here’s a verbose equivalent which is a bit more self explanatory:

Seq.tabulate(3, 9)((x: Int, y: Int) => new Cell(x, y))

And now go get it and have a lot of fun!

Mac Tips & Tricks #7: GIMP

Unless you are a proud owner of a Photoshop license (or a not-so-proud owner of a PS crack), GIMP is probably your best bet when it comes to professional image editing software. It works on all platforms, the OS X version can be downloaded here.

GIMP uses a multi-window layout. On the Mac, it requires Apple’s X11 window environment (which explains, why your menu bar will say “X11″ once you launch GIMP). Unfortunately, X11 has a very annoying behavior by default: If you click on an inactive window, the click will just focus that window. Say you want to select a different brush from the “Toolbox” window, this requires two clicks: One to activate the window, another to select the brush — for me, this made GIMP unusable on the Mac at first.

Luckily, I stumbled across a hidden X11 preference which does the trick:

X11 Preference

After this is ticked, GIMP & X11 cooperate just as you would expect them to!

Mac Tips & Tricks #6: AppleScript

From Wikipedia:

“AppleScript was designed to be used as an accessible end-user scripting language, offering users an intelligent mechanism to control applications, and to access and modify data and documents.”

Yet another scripting language — but honestly, the fact that it is built into Mac OS (no installation) and was initially designed to automate repetitive tasks, makes the getting started quite easy & fun.

Here’s my problem (and how I managed to solve it with AppleScript in about 30 minutes): As you might know by now, I am a happy Quicksilver user and I sometimes take it as a challenge to do as much of my programming & office work via keyboard as possible. One task I regularly do throughout the day, is creating “Task” entries ;-) I do this via the “Mail” application, which eventually adds its entries to Exchange, so they are accessible from any machine/device. Long story short, adding tasks should be simple via Quicksilver, given that it can cope with textual input and pass it on to any AppleScript. Here’s the todo.scpt that I came up with (aka structured procrastination):

using terms from application "Quicksilver"
 on process text inputText
  tell application "Mail" to activate
  tell application "System Events"
   keystroke "y"
      using {command down, option down}
   keystroke inputText
   key code 36
  end tell
 end process text
end using terms from

Or in other words:

# use Quicksilver's dictionary
# Quicksilver's script handler
# bring up "Mail"
# access keystroke functionality
# create TODO item via keyboard
# with modifier keys
# insert text from Quicksilver
# enter

To try it out yourself, just store the script in ~/Library/Application Support/Quicksilver/Actions and invoke it as usual:

  1. Invoke Quicksilver and press period to go to text entry mode
  2. Enter your task (e.g. “Remember the milk”)
  3. Hit tab and start typing “todo” until the script action shows
  4. Hit Enter and watch your task being created

I am confident that you can come up with even better AppleScript usages to waste the rest of your day ;-)