Friday, October 9, 2009

Closures in Python and JavaScript

Here is a program written in Python:
def clo():
a = 3
def geta():
return a
def seta(newa):
a = newa
return [geta, seta]

closure = clo()
And here is the same program written in JavaScript:
function clo() {
var a = 3;
function geta() {
return a;
function seta(newa) {
a = newa;
return [geta, seta];

closure = clo()
Here is the output of running the Python program:
tuba:~ litherum$ python --version
Python 2.5.1
tuba:~ litherum$ python
And here is the output of running the JavaScript program:
tuba:~ litherum$ java -jar Downloads/rhino1_7R2/js.jar test.js
Here are a couple observations of this:

  • Both languages printed out a value, so clearly both of them use closures

  • Python printed out the original value of a, so it appears that it creates a new closure for each function invocation.

  • JavaScript printed out the new value of a, so it appears that the closure is consistent across function invocations

I just noticed this and thought that it's fairly interesting food for thought.

Saturday, October 3, 2009


Joel Spolsky gave a talk at his business of software conference on making a number one product. One of his main points was this concept of misattribution, or trying to get people to feel that their happiness is caused by your software product, even if it may not be.

My own understanding of misattribution goes something like this: Say I'm going out on a first date to a restaurant with a girl. I want this girl to like me, so on the drive to the restaurant, I put on some music that I know she likes. Music provides a line directly to the emotional part of the brain, something which ordinary speech can not do. This music starts off the date by putting her in a good mood. Now, assuming I don't do anything particularly fiendish during the date, her general good mood should stick around. On the way home, the music once again cheers her up. When she arrives at home, she thinks back about the night and believes that because she was in a good mood for the entire evening, the date must have gone well, and therefore the two of us might be at least somewhat compatible. The kicker is this: she misattributed her feelings of happiness from the music with her feelings of me.

Now take this to the software world. What is actually happening here, when you woo your girl by putting on some Barry White? You are creating an experience. Experience is the entire night out at the restaurant; experience starts when you first hear about a product and ends when you last think about it. The iPod has been lauded and heralded so much lately, but I must say that Apple really has the experience down right. The package your iPod comes in is crisp and clean. Your iPod pops out of the case like it is from the future. Apple understands that, to a general user, it does not matter how many gigawhatsits your new processor has or how many megawhosings your monitor supports. They realized the power of misattribution early.

Every geek knows the slight joy felt when one end of a wire fits perfectly into another end of another wire. The pieces were simply made to fit together, and when you plug them together everything fits perfectly. This is the joy of unwrapping your new iPod: everything just seems to fit together in a way that makes it seem right. I know I like rounded corners, which the iPod employs. This does not make it play music any better; I just like rounded corners. I enjoy using my iPod partially because of the overall experience. Apple has found a way to make me misattribute my happiness of things fitting together correctly for my feelings of using an iPod.

At first glance, the concept of misattribution seems like trickery: Make the user think that your product is good by putting something shiny next to it. However, when Joel Spolsky says that we should make our users misattribute their positive feelings to our products, I believe he means that we should create an entire experience for our product. Do not simply make a product with X, Y, and Z features. Instead, think about how the user is going to interact with your product and make a sort of meta-product: one which you are not selling directly but is nevertheless sold with your product.

Last summer I read a blog post about the distinguishing factor between enterprise software and non-enterprise software. The main point the post made was that, for standard commercial software, the burden of integration is on the user. Okay, Fred, if you want to use Microsoft IIS, you have to figure out where it is going to run, how it is going to run, what software is going to run on top of it, and you have to hope that using this software is going to solve your problem. In enterprise software, you must act much more similar to a contractor - you are no longer selling a product but now selling a solution to a problem. It is now no longer up to the company to figure out how your product is going to solve their problems; It is up to you to actually solve the company's problems with your product.

This ties in completely with the aforementioned topics of misattribution and experience. Enterprise software has to work at a higher level than simply selling a product; they have to create a meta-product to sell to their customer. If you solve a company's problem with minimal overhead, the entire experience will be positive for the company, and they will misattribute their positive feelings onto your product, even if it is not the best product out there.

This describes a fundamental shift of computer programs: the best programs are not products but are instead services. They create an entire experience for the user and solves the user's problem without the user's intervention. If they do their job well, users will love it, even if it lacks some features.

Which would you rather drive: a crappier, more fun car? Or a car that goes faster but smacks you in the face repeatedly and requires intense concentration to drive?

Evil Corporation logos

As far as logos go, I place an extremely high value on elegance. Making an elegant logo, however, is a difficult task. Here are a couple things that I think can help:
  • Smooth, clean lines
  • Repetition of a theme
  • Simplicity
  • Few colors

I was playing Prototype the other day and the thought struck me: Evil corporations in video games generally seem to have extremely elegant logos. Here are 3 examples:

  • Umbrella Corporation from Resident Evil:

  • Gentek from Prototype (This is the best one I could find):

  • Armacham Technology Corporation from F.E.A.R.:

Decide for yourself, but I think that if I ever have to make a logo, I will use these as a starting point. Hopefully I won't be in the process of creating my own evil corporation :)