Thursday, February 26, 2009

Hangover Cure

Here's a round-up of recent chatter about one of my favorite subjects, the life and death of cities. First, there's Richard Florida's piece from The Atlantic and his discussion of that piece on On Point (listen for the Providence shout-out around the 39 minute mark). Finally, some dueling viewpoints grabbed from the NYT Op-Ed page.

I think Florida could clear up a lot of confusion about his ideas if he stopped using the words 'city' and 'suburb', because those terms are so loaded that it's easy to stop listening to him once he says something that conflicts with your interpretation of those words. Florida is often criticized by people who think he's saying that everyone needs to trade in their 4 bedroom suburban home on a 2 acre lot for a 500 sq ft apartment in a high-rise. I don't think that's what he believes and I think he finally articulates his vision at the end of the On Point interview when he says Americans need more efficient ways of living and moving around. Efficient in terms of energy, but also in terms of time and effort. Innovation requires a critical mass of human capital that can interact in seamless and chaotic ways. If everyone is stuck in traffic for an hour and a half on their way to an office park in the middle of nowhere, time is being wasted and opportunities for innovation and collaboration are being squandered (not to mention the big decrease in quality of life).

Obviously there are a lot of people who are happy with the status quo and will continue to abide by it even in the face of multi-hour car commutes and $4+ gas. That's fine, but I think what Florida is saying is that there are a lot of people who would like some saner options for balancing life and work and areas that can provide these options will likely fare better than those that don't.

Wednesday, February 25, 2009

Good and Bad

The first no-hitter than I experienced was the no-hitter that the Tigers' Jack Morris pitched in 1984. It was the first no-hitter pitched by a Tiger since Jim Bunning hurled a no-no in 1958. Being a young Tigers fan, I filed this piece of information somewhere in my brain and didn't think about it again for a while. At some point in my adult life, I learned Jim Bunning had gotten into politics after hanging up his spikes. More recently, I've learned that he's kind of a jerk. I don't have anything interesting to say here, it's just funny how I have a one highly positive and one highly negative data point about Jim Bunning, separated by about 25 years.

Monday, February 23, 2009

Deposed

Sadly, it appears that Parade Magazine has decided to discontinue their annual survey of the world's worst dictators. It's possible that they've decided to move the feature from its usual mid-February spot, but the World's Most Wanted cover story that they ran a couple weeks ago seems a lot like a replacement for the worst dictators feature.

Friday, February 20, 2009

Empty Bench



February 19 | 7:22 pm | Providence, RI

Thursday, February 19, 2009

Stream of Consciousness

I've been taking a look at functional programming languages in general and Scala in particular as of late. Partially because I've been sucked up into the hype surrounding FP & Scala and partially because I've never really done any FP. I read this post about infinite lists in Scala a couple months ago and decided that I wanted to try and do something similar with files. My goal was to create a function that takes a directory and returns a lazily evaluated list that can be used to recurse through every file and directory under the directory. Here's what I came up with:


import java.io.File

def makeFilestream(filelist: Stream[File]) : Stream[File] = {
if (!filelist.isEmpty) {
val file = filelist.head
if (file.isDirectory) {
Stream.cons(file, makeFilestream(file.listFiles.toStream.append(filelist drop 1)))
} else {
Stream.cons(file, makeFilestream(filelist drop 1))
}
} else {
Stream.empty
}
}

def filestream(root: File) : Stream[File] = {
val filelist:Stream[File] = root.listFiles.toStream
makeFilestream(filelist)
}

So what's the point of all this? By using Scala's Stream class, the list is lazily evaluated so it doesn't have to scan the entire directory tree before returning the first element. Furthermore, since Stream behaves like any other Collection class, all of the normal Collection operations like foreach, map, reduceLeft/Right, etc. are supported, eliminating the need to load the directory tree into memory and storing it in a List before operating on it.

Here are some examples of the cool things you can do with a file stream

Print everything in the directory /tmp

val tmpdir = filestream(new File("/tmp"))
tmpdir.foreach(println)

Print the first 10 directories under ~

val homedir = filestream(new File("/Users/username"))
homedir.filter(f => f.isDirectory).take(10).foreach(println)

Find the largest file under ~

val homedir = filestream(new File("/Users/username"))
val biggestFile = homedir.reduceLeft(
(a, b) => if (a.length > b.length) a else b)

Find the first Java source file under ~

val homedir = filestream(new File("/Users/username"))
val firstJavaFile = homedir.find(f => f.getName().endsWith(".java"))


Pretty much any file searching, selecting, or transformation operation you can think of can be expressed as a one-liner or chain of one-liners and thanks to the Stream, any operation that doesn't need to scan the entire directory tree is fast and efficient.

Thursday, February 12, 2009

The Roof is on Fire

We saw Fiddler on the Roof at PPAC last night. It was my first time seeing Fiddler. My family went to see the local high school's production of it when I was 13, but I had no desire to see a musical or hang out with my parents and I managed to weasel my way out. Since then, I've developed more of an appreciation for musical theater (as well as being seen in public with my family). I went into the show with high expectations and I wasn't disappointed. Compared to most musicals that I'm familiar with, Fiddler on the Roof is more understated and dark. I enjoyed that and I also enjoyed seeing Chaim Topol playing the role that he's played for the past 40 years. I've always wondered how actors can play the same role night after night. It seems like it would get boring after a while. If Topol is tired of playing Tevye, it didn't show on stage. You could really tell that he was enjoying himself up there and his performance exuded a lived-in kind of quality that an actor who has only been playing the Tevye for six months (or even six years) wouldn't have.

Sunday, February 08, 2009

Who Wants to be a Best Picture?

We recently made it out to see what all the hype surrounding Slumdog Millionaire was about. It's an enjoyable film, but neither of were really blown away by it. Visually, it's quite gorgeous and the story is endearing, though predictable. It's a good movie, but we probably wouldn't have nominated it for 10 Oscars had the academy asked us.