Tuesday, June 21, 2011

Django in 20 mins

During one of my StartupWeekend experiences, my team used Django and Python to create the prototype web application. They did a fantastic job in a short period of time. I have always worked with Java, Javascript, Struts, Hibernate, etc. but had not ventured into the server side technologies like Ruby, PHP, Python, etc. So, I thought it is a good time to catch up on these technologies so that I can better understand them. I am always a firm believer of getting my hands dirty in order to fully appreciate anything, be it technology or art.

This week, I decided to learn Django and Python.

I looked around the web and found a site which promised to teach me to build a web site using this technology in 20 minutes!! Awesome, I thought. No wonder it has become so much easier and faster to develop web apps. I watched the video here, and it seemed pretty straight forward and easy to try out. The rest of this post is about my saga to build this sample Wiki application using Django and Python.

One thing I realized after spending several hours (not minutes) to get up and running is that the tutorial completely misses out on the pre-requisites. It assumes that all the pre-requisite software is already installed and configured. That is where the problem started. I didn’t have any of the pre-reqs (apart from mySQL database server, Tomcat, Eclipse and others) installed. Note that I was trying this project on a brand new 64-bit Windows machine.

First thing I had to do was to get Python. I downloaded Python 2.7 and installed it. Then, I downloaded Django and installed it.

Python, for some reason, doesn't append the Path env variable. I had to manually add Python to the Path. Once I had these two in place, I created my project and started configuring it. Trying to connect the Django model to the database is when I realized that I didn't have a connector for Python to talk to MySQL. I looked around and found MySQLdb from SourceForge and downloaded that. The beauty of this is, it is not available as a binary. So, I had to download the source and build it. I try to build it and lo and behold, I discover that I don’t have a compiler. Since I did not have access to Visual Studio, I downloaded MinGW, the open source compiler. I ran the 'setup.pl build' utility and hit many more errors. After several iterations, I was able to finally build it. I run the executable and it complained that I don’t have Python installed. Duh. I know that Python is on my machine but this sucker is not recognizing it. After a bit of research I found that Win64 sticks the registry values for 32bit apps under Wow6432Node. Thanks. Now, I had to correct this or add the correct registry entries. I created a .reg file and added the correct entries. Ran regedit and was able to add the correct registry entries. Now, the MySQLdb installation was able to complete successfully. Phew.

The video also forgets to mention that the database needs to be created before running syncdb command. I ran the command and after seeing the errors, went ahead and created a new database in mySQL and ran syncdb again successfully. I now had the database tables created.

Success at last.

I am now able to build my app. I start the server and hit more errors. Runserver craps out with error that it cannot access socket. This may be due to the fact that Windows 7, with UAC, administrator accounts run programs in unprivileged mode by default. So, programs must prompt the user and get permission. But, since python scripts aren't directly executable, they cannot prompt the user. Hmm…

After more research, I found that the default port was already in use and that was the real issue. I called runserver with another specific port and everything worked fine. Phew. Now, I have the server up and running.

I went ahead and completed the application and ran it successfully.

I discovered that most of this open source software is yet to be ported to Win64 and hence these problems. I also discovered that lots of people have come across the same errors I encountered. Is it due to lack of documentation? Not really. Django has a tonne of great documentation. I just need to make time to read it all. I was too eager to get the application up and running.

But, there are lots of resources on the web to help you surmount the problems.

All in all, Django and Python are great for quickly putting up a prototype web application. I am really impressed. I still need to see how well it scales, though.

But, don’t be fooled by the video claiming that it takes only 20 mins to get up and running. It took me more like 3-4 hrs starting from scratch. Maybe, because, I had a 64 bit machine and was running Win 7. Or, maybe because these things do take some time to wrangle and set up correctly. I am hoping that it will be clear sailing from this point onwards.

Looking forward to more web app development.

Follow up comments (Jul 2011):

I did look into the Django as well as Python documentation and they are fantastic. The documentation is extremely detailed and is available in many formats. Kudos to the team that put this documentation together. Top notch.

Light Field Photography

Lytro, a Bay area startup announced their product to the world today. It is great to see innovation in the area of photography. Yes, we did go from film to digital, but what changed was the medium of capture of the data and nothing else. What Lytro promises is a new way to capture image data, one which captures light fields from multiple angles and lets the user manipulate the data after the fact. Check out their gallery for some stunning examples. This is really cool technology and I am waiting to get my hands on the camera.

The marketing message for this camera seems to be centered around 'shoot first, focus later'. Before auto-focus was invented, people focused cameras manually. But, once auto focus was introduced, how many of us focus cameras manually, especially, consumers. Auto focus was a boon to the camera world and paved the way to make photography an enjoyable experience, and we saw an exponential increase in consumer adoption. Digital photography (immediate gratification) took it to the next level. Now, Lytro wants the consumer (viewer of the end result) to 'focus' the picture in order to enjoy the 'living picture'. I don't think my friends and family would want to 'focus' my pictures and discover the hidden details.

The beauty and art of photography was that it allowed the artist to tell a story in the way they want to tell it. This new technology is akin to the 'create your own adventure' books where you decide how the story turns out. How popular are those books? Not very..

The light field technology and camera does have its uses. Imagine a traffic/surveillance camera equipped with this technology, and the CSI computer geeks will be out of jobs.

The success of this company will depend on how they productize the technology and market it to the consumers. The current story is not compelling enough to tilt the scales.

Monday, June 13, 2011

Lessons from StartupWeekend

I have attended a few StartupWeekend events and it is always exhilarating to participate in them. All the energy and enthusiasm is contagious to say the least.

One pattern I have noticed so far is that a majority of the projects just fizzle off, after the weekend. One of the main reasons is the fact that the team realizes that the idea is either not feasible or does not make sound business.

In reality, VCs always look for 'the team'. If you have an A-team, come what may, they will execute. If halfway through the endeavor, they discover that the idea doesn't hold water, they will come up with another one which will. Remember, they are the A-team.

The biggest problem at StartupWeekends is that there isn't enough time to iterate, and come up with fresh ideas. You present an idea on Friday, and have two days to execute. If the Product Manager determines that the idea doesn't make business sense, it is too late to turn the ship. The developers are already half way through the project and are not going to stop. Even if you stop, and change course, the chances of having a demoable application by Sunday evening is pretty slim. So, in order to save face, the team moves along and completes the implementation (demo app).

After the weekend, the idea fizzles off since the momentum is lost and no value is seen in continuing the idea. In cases where there is a lot of synergy and great teams are formed, they continue to meet and hash out ideas that they finally implement.

So, the key to a successful StartupWeekend is not the idea, per se, but the team you form. Next time, pick people who complement you and make a great team and success will follow.