The two options: Game development or boring database stuff

When I was thirteen years old, I thought programmers fell into two categories: game developers and boring, big-business enterprise developers.

"Yeah, in enterprise stuff, you just program a GUI and people can put data in, like their name, their salary, their boss' name, and their boss' salary," I explained to my brother. It was because the programming books always used employees and bosses as examples. So I decided that I would become a game developer. I was thirteen.

When I entered university, I chose computer science as my degree. By this time, I had lost interest in gaming, but I still loved programming. I would program games for fun, because it was either that or database programming, and MySQL seemed hard. And I knew that writing HTML wasn't actually programming.

I took a basic data structures class and a basic logic class my first semester in university. It was fun, but the end of the semester, I started to dread my future as a boring database programmer. I thought about switching majors. History, perhaps, or writing. Or music composition. I wanted to create, you see. I wanted to create beautiful things. I had written short stories and pieces for piano and orchestra, and it was always so fun. I started on a symphony, but realized that I didn't know much, so I never finished it.

Then I found out that my professors weren't teachers; they were researchers. I didn't know how you research something, but I figured that research was better than boring database programming. So I took a course on autonomous vehicles my second semester and I started reading research papers on how cars can drive themselves. I stayed on campus for the summer on a research fellowship and continued my work. I coded my algorithms and ran my experiments. My work didn't improve on anything, so I threw everything away. That's research, I supposed, lots of throwing stuff away.

Then I started to read. I found Paul Graham's essays. I learned the word "startup." I realized that there is a bigger world out there. And I found that creation is still possible, that programming can be beautiful.

Why UT Austin is second-rate at producing startup founders

The author is a fourth-year student doing a Bachelor's and Master's in CS at the University of Texas at Austin. This essay refers to UT's computer science undergraduate program.

Paul Graham argues In his essay How to Be Silicon Valley that you need two types of people to produce a high-tech community: rich people and nerds. Nerds come from universities with good computer science programs.

The University of Texas at Austin Computer Science department (UTCS) is a top-10 computer science program. So why aren't more startups coming out of UTCS? There are several reasons.

First, our professors think that getting a job at a big, stable company is a good thing. Is it? Bruce PorterMichael Walfish, and William Cook are the only professors that ever mentioned the word "startup" to me. This is unfortunate. Companies love to harass CS departments. Teach them less theory and more Java! No, wait,  teach them machine learning and complexity theory! Instead of wilting under the pressure of companies starved of good CS graduates, UTCS needs to push their students away from boring, monolingual (Java, of course) programmers and into true hackers. I've had many friends that graduate from UTCS with only Java and Haskell on their resume because that's what UT teaches. And they don't really know Haskell, I promise you.

But the point is not to teach them more languages. Java is fine. Haskell is fine. We need to fundamentally change the way UT computer science students look at our industry. This can be done by a mandatory one-hour seminar on technology companies, old and new. Make them read Paul Graham's essays. Make them learn how companies get angels and VCs to invest. And start them young, right from their first semester of freshmen year. This course will help UT identify and nurture future startup founders.

Second, UT's computer science undergraduate curriculum has little emphasis on building real-world product. Yes, UT is very good at getting undergraduates to do research, but research is not the same thing as building a startup. Make students build a startup. Create a course that is cross-listed with business and marketing students with a 3:1 CS to business/marketing student ratio. The students should then split up into groups of four consisting of three programmers and one business/marketing student. Within the span of the semester, each group must build something sellable and pitch it to investors, professors, and entrepreneurs. At least they'll learn version control. (I've met seniors that have never used version control!)

Graduate students like Joel Hestness and Thomas Finsterbusch have petitioned for such a course, but from what I've seen, there is little hope of this becoming a reality anytime soon, mostly due to lack of support from professors.

Third, UTCS has a "good enough" attitude when it comes to competing with other top schools such as MIT and Stanford. It seems that UT computer science is satisfied with a high post-graduation job-placement rate among their 1,000 (and growing [is this a good thing?]) undergraduates. What UT needs is a more competitive attitude. Yes, MIT and Stanford get smarter students than UT. And yes, the best companies, old (e.g. Google, Facebook, Apple, Microsoft) and new (e.g. Yelp, Zynga), descend upon the best UT graduates. But why is UT letting Silicon Valley lure the best and brightest away from Austin? Because they believe that Austin cannot match the experiences and opportunities of Silicon Valley. It is up to UT (and Austin companies) to prove that Austin can match with Silicon Valley.

And finally, there is no startup "buzz" around UTCS. None at all. Compare that to Stanford's CS program, where students can take classes like Web Applications and iPhone and iPad Application Programming and Cloud Computing (look at that list of top-notch guest lecturers!). Oh, but UTCS isn't a trade school! How dare we teach our students iPhone programming! But Stanford's campus is teeming with students passionate about starting awesome companies. What about our campus? At UT, I just hear people complain about the difficulty of using version control.

One reason for this embarrassing lack of buzz is that Austin startups differ from Silicon Valley startups. Successful Austin startups, it seems, are usually B2B, and thus unknown to the common student, and use not-so-sexy technologies like Java, which drives passionate students away.

I have met some students passionate about startups, but their numbers are few.

We can fix this by building partnerships with Austin's great entrepreneurs. There was a great invite-only entrepreneurship seminar last semester (but not this semester) headed by Andy Maag, CTO of Bazaarvoice. It's sad, really, that UTCS depends on others outside of UTCS to get things like this started. UTCS, get some money, get a guy to run it (Andy has other things to worry about, like running a company), make this seminar public, give out free food, and make it a party! That $300 spent on the Chipotle catering (pizza is lame) is worth so much more than $300.

People like Bruce Porter, the current chairman of the CS department, and programs like 3 Day Startup are working hard to improve entrepreneurship at UT. But we can't fix this problem with just more programs and seminars. We need a fundamental change in the way we think about and raise our undergraduates. Only then can UT begin to produce startup founders.

Thanks to Michael FairleyPaul Roberts and Jason Bradshaw for reviewing this essay.

Post-script: I am not advocating a software engineering degree; I prefer a computer science degree. I am not advocating a Silicon Valley in Austin. I know the resources are out there. The problem is that UTCS students don't understand what startups are and thus do not take advantage of Austin's great resources.

Git for Humans: Patching Your Commits

Ideally, every git commit would contain one logical work. But we don't work this way. We often get side-tracked from our current task. In the middle of a bug fix, we may see a method vulnerable for refactoring. So we refactor it.

 And now we have to commit a bug fix and a method refactor, and they're both in the same file. The lazy way out would be to commit the file with a nice message: "fixed bug #183 and refactored method_name".

But can we do better?

Yes. With the --patch option, we can precisely choose which hunks of code we want to add into the staging environment:

$ git add -p
diff --git a/README b/README
index 9938af1..88f41c4 100644
--- a/README
+++ b/README
@@ -1,3 +1,4 @@
+Version 1.2
-Version 1.1

Stage this hunk [y,n,q,a,d,/,e,?]? 
Not surprisingly, the --patch option works for other git commands like git-checkout, which would allow us to precisely choose which hunks of code we want to discard from our working directory.

So use --patch and make your commits precise.

 

Setting up Vimclojure

Clojure is a fascinating language, but setting up a nice, vim-based working environment is a pain. I finally managed to get vimclojure working (vimclojure 2.2.0-SNAPSHOT with Clojure 1.2), and I hope my notes will help you set up.

Download and Build Vimclojure

$ hg clone http://bitbucket.org/kotarak/vimclojure
$ cd vimclojure/client
$ make

Now, we need to download the server (it was recommended that you don't build the server yourself): http://clojars.org/repo/vimclojure/server/

Copy the server jar to vimclojure/server/server.jar.

Set up vimrc

First, we copy the vim plugins into our local .vim folder:

$ cd /path/to/vimclojure/vim
$ cp * ~/.vim/

Then, we modify our .vimrc to enable vimclojure:

$ vim ~/.vimrc

syntax on
filetype plugin indent on
let vimclojure#HighlightBuiltins = 1
let vimclojure#WantNailgun = 1
let vimclojure#NailgunClient = "/path/to/vimclojure/client/ng"

Run the NGServer

To run the NGServer, we need to specify the classpaths of our code, the clojure jar, and the vimclojure server jar:

$ java -cp /path/to/your/code/:/path/to/clojure.jar:/path/to/vimclojure/server/server.jar vimclojure.nailgun.NGServer 127.0.0.1

Mine is:

$ java -cp .*:/path/to/clojure.jar:/path/to/vimclojure/server/server.jar vimclojure.nailgun.NGServer 127.0.0.1 

Using Vim

After this, we can open vim and edit .clj files (inside /path/to/your/code/). If we want a blank buffer, do:

:setfiletype clojure
\sr

Send it to be processed by clojure by hitting \et to process the current line or \ef to process the entire file.

References:

http://groups.google.com/group/vimclojure/browse_thread/thread/69abeea9f57cb73b/9360432c165c2beb

http://groups.google.com/group/vimclojure/browse_thread/thread/168da4c737d084e1/e0a668d25c3e4aef?lnk=gst&q=filenotfoundexception#e0a668d25c3e4aef

Singleton Pattern in Python

Sometimes, you find that you only want one instance of a class to be created. Ever. This way of programming is often referred to as the singleton pattern.

In languages like Java, the singleton pattern is often implemented by using a class static variable as the single object:

In the snippet above, the default constructor is set as private so to prevent the user from instantiating a OneOnly object. Instead, the user must use OneOnly.get() to get access to the one and only OneOnly instance.

This way of executing the singleton pattern is impossible in Python due to the fact that Python does not have an equivalent to Java's final keyword.

A well-defined singleton pattern, however, is possible in Python. The Wikipedia entry on the singleton pattern [1] presents a clever way of doing it in Python. I reproduced Wikipedia's Python example below and added some more code to explain what's going on under the hood.

In the snippet above, singleton() is a function that takes a class and returns a function. I created a simple Counter class. Line 15 shows that Counter is a class. I then set Counter to the return value of singleton(Counter). Counter is now a function, as Line 17 shows. This is awesome. Now, whenever the user tries to "instantiate" a Counter, the user is really just calling a function, namely getinstance(). And getinstance() is built so that it will only build one instance of Counter, on Line 5. If an instance of Counter already exists, getinstance() will simply return that instance.

The Power of Closures

But why does getinstance() work? The most amazing part is that the getinstance() that is set to Counter is a specific getinstance() that "closes over" the variables cls and instances. That is, when we define getinstance() inside of singleton(), getinstance() still has access to cls and instances, even after we exit singleton(). Thus, we don't have to create a new instances dictionary every time. This only happens once, at Line 2. We get to Line 2 through the call at Line 16, which only happens once (for Counter).

Why does instances have to be a dictionary? Well, it doesn't. The only thing that matters is that we don't set the instances reference to a new object somewhere inside getinstance(). If we do, we lose the closure over the instances defined on Line 2. Thus, instances should be a mutable object such as a dictionary or a list.

Let us test our singleton object:

As you can see, every call to Counter() returns the same Counter instance. Great! We now have a very powerful construct to build classes that adhere to the singleton pattern. If we want to create another one-instance-only class named Puppeteer, we simply set Puppeteer = singleton(Puppeteer) after the class definition. Puppeteer will then get its own getinstance() function and its own instances dictionary, separate from Counter's.

Decorating

Python has something called decorators. A decorator is just syntactic sugar [2] for what we did when we wrote Counter = singleton(Counter), which can look a bit ugly. We can prettify this by adding a @singleton before our Counter class definition:

If you haven't seen decorators before, you should now realize that a decorator @singleton will simply set the class name (in our case, Counter) to the value returned by singleton(Counter).

Conclusion

So yes, Python's open nature is sometimes unwanted. But with closures (e.g. getinstance() closing over cls and instances) and first-class functions and classes (i.e. passing around classes and functions as ordinary objects), Python allows us to device beautiful, clever constructs.

References

[1] http://en.wikipedia.org/wiki/Singleton_pattern
[2] Python Decorators Don't Have to be (that) Scary. http://www.siafoo.net/article/68

Behind Python's unittest.main()

Is Python magical? Consider the trivial unit test below:

Unless you're a Python guru, I'm sure you've wondered how unittest.main() found and ran TestSomething and TestSomething.test1. If you look at the unittest source code, you find a nice trick:

Ah, unittest.main isn't a function, it's a class! So unittest.main() creates a new TestProgram object, whose initializer then goes ahead and runs the unit tests for you. But how does TestProgram know to load the TestSomething class and run TestSomething.test1?

Most of this work is done by the unittest.TestLoader class. TestLoader will look at the current module (i.e. your current file), examine each class in it, and load classes that inherit unittest.TestCase. Then, TestLoader will look inside these classes for methods that have 'test' as their prefix.

After this, TestProgram will know what tests it needs to run.

Of course, unittest is more complicated than this, but this describes the main flow of unittest. I suggest that you download the Python source code and read unittest.py yourself. It's a lot of fun, really. Plus, reading source code is a great way to improve and enrich your coding, and Python's source is one of the best treasures around.

Why, Hello There!

And thus is born another green giraffe. What is a green giraffe, one might ask? It is a pasture, really. A luscious, green pasture of thoughts, ideas, and code. A place where a human and a machine may forever dance beneath a never-setting sunset. A dream.

The Green Giraffe in its proper noun form, however, is this very website. It is merely an attempt at birthing this elusive green giraffe. I am no conjurer of beasts, but perhaps with some work and thought, The Green Giraffe will manifest itself and become a useful resting place for you coding wanderers.