Friday, September 5, 2008

Programming: The finest steel has to go through the hottest fire

As the college season is in full flow, I'm back to my philosophical self and I've something for my students... Last week, I was conducting the regular Assembly Programming practicals, where I'm supposed to teach students 8085/8086/8051 ASM programming. Now, as much as I love programming and finding solutions to problem, I also love another thing: Creating problems for others to solve... and even if I know the answers, I would never give away the answer... come what may!!

So we started with all the instructions, available registers and memory allocation. Somewhere down the line, we started with a program to multiply 2 numbers. Now, as simple as I thought it was, my students didn't seem to think the same way. I told them that repeated addition was actually multiplication and they affirmatively nodded their heads, but the program wouldn't just come out from them. After close to an hour and me giving them numerous hints, we were still stuck at the loop!! They demonstrated it easily in a single line of C or C++ or Java, but ASM wasn't just clicking. That's when I affirmed, "Don't worry, programming doesn't come naturally to anyone... We all learn it our own way!!" And the class was stunned, similar to what I've seen at my office's training sessions... and the next question most of the times is, "Then how does it come naturally to you ??"...

"The finest steel has to go through the hottest fire!"... I read it somewhere, but then that's what is true about your individual talents. A singer's voice, a painter's hand, a composer's notes, a poet's verse... all may be claimed to have come from God or by birth, but its the desire to overcome obstacles and practice is what makes them achieve perfection.

Programming is very much an acquired skill, just like most things in life. Even logic for that matter doesn't come by birth. As we observe others follow a pattern of doing things, we follow that same pattern. The more we do the same thing in a way that is acceptable to our intellect, the more it becomes part of our existence and more natural the action becomes. When we first learn to speak, we probably think its harder than anything we have done before. Now as we know to speak, its easier than easy. Same is with programming. The more code that we observe, the more code we write, programming becomes more natural. Whoever says that logic to solve problems came easy, is either boasting his own ego or hasn't thought logically about it.

I was at the vegetable vendor the other day, who was talking of a way to solve the Bihar floods which made some 20million people homeless. His solution sounded really promising and as I know him for some years now, I knew he was intelligent. Huh... I wondered if programming would come naturally to him. He had never seen or used a computer ever but had passed high school. So if he could find a solution, it would mean that programming (read: finding solutions) came naturally to him. So, while he was selling vegetables, I sat beside him and blabbered the same things, I had told to my students at that lecture, but this time it was in Hindi and avoiding most tech-words. While I was speaking, I didn't even know if he was listening... He was busy selling vegetables, with his ~10yr old son and the aunties that came by kept smiling while looking at me. After a while, I asked him if he could multiple 2 numbers, given the instructions I explained... He thought for a while, picked up a few ladies finger (those long green vegetables), which he represented as instructions and explained me a perfect program to multiply numbers, not just 8-bit or 16-bit that would fit in a register-pair, but a multiplication program that would store larger numbers in ordered memory locations... Wow... that was superb!!... Unbelievable and brilliant, I said to myself!! I told him real instructions like ADD r1 r2, MOV r M,  ... and I told him to use those instructions and make a program to calculate modulus of a number. Hmmm... he thought for a while, but this time couldn't find a solution. He asked me many questions though, which he thought would give him an answer... But alas, no solution was found!!

I went back home and realized that may be it is the mumbo-jumbo words that divert our conscious efforts to find a solution. It may very well be the emotion of success that stops us from continuing to find the next problem and its solution. My students had passed earlier classes with 90% and more marks and were among the best students academically in the city.  Did that success get to them ??... Whatever it was, I realized persistence to find an answer to a problem gave us much better understanding of ourselves... May be programming teaches us to understand ourselves better than the problem at hand!!

Wednesday, September 3, 2008

A Look At Free/OpenSource Cross-Platform Installers

Software Distribution is an essential part of Software Development and can sometimes be the first impression that can make or break the user's opinion about a software. We, as software programmers forget the importance of easy distribution and easy installation of software that we develop. We do not understand the problems that a new computer user or a non-programmer may face. And I experienced this first hand about 2 weeks back, when a physician friend of mine heard that I was working on OpenMRS.

I was lucky enough to work on OpenMRS this summer and learnt a lot more about Medical Informatics during this period than I expected. Hearing this, my friend openrmswanted to install OpenMRS at his clinic which already used Tally (hehe... isn't that innovative??) for storing patient records, observations and prescriptions. He practices at Kolkata, visits different hospitals and sometimes the patients he attended at a hospital come to his clinic. When I told him that OpenMRS was a webapp, he got all excited and I narrated him all the features that OpenMRS could provide and help him manage his patients better through the web, only if he could host OpenMRS from his clinic. I'll skip the other interesting parts and his extra-terrestrial expressions ;-), since we are actually talking about software distribution.

So then came the day when I was about to leave office and he was in his clinic trying to install OpenMRS. It was Independence Day and the clinic was closed but he was excited to experience the new-age medical informatics :-)) When I first got his call he had downloaded the Windows Installer. I was pretty sure it was for an older version and hence told him to instead download the OpenMRS Appliance, which is a VM Image that can be run from one of the virtual machine softwares. Yaw Anokwa made this wonderful Virtual Image with Ubuntu + All Necessary Stuff (tomcat, mysql, demo data) and OpenMRS running. You just have to have VirtualBox or VMPlayer or VmWare Workstation and load the VMimage and wait for Ubuntu to start. It is simple, fast and safe to play with... But for novice users, I just realized it wasn't easy enough. My friend installed VirtualBox and loaded the image. It booted fine, but the network wasn't working and OpenMRS webapp could not be reached from the Windows host. After being on call for close to an hour, we just couldn't make the networking work!! I advised him to install VMPlayer instead and run the image. This time everything ran fine, but some changes had to be made in the Norton 360 Firewall. He kept complaining that Windows XP was punishably slow and then I realized that his 512Mb wasn't enough to virtualize :-( ... So we were back to where it all started!! The Windows Installer that OpenMRS distributes is based on Bitrock. He first tried the OpenMRS 1.1 Installer, but it is an older version that hasn't been upgraded for a year or so... Everything installed fine and he was happy to use it, but it didn't have the features I talked about that were added in newer releases of OpenMRS. I walked him through the manual installation and finally we managed to get OpenMRS up-and-running at 2am in the morning and he having spent about 8hrs on it. Last week when I asked him, he still wasn't using OpenMRS for his clinic and hospital. May be the first experience made him bitter!!

With that episode in my mind, I pledged him that within the next month or so I'll give him and easy to install setup and he'll be happy using OpenMRS. And that's when began my chase to find an easy to use, cross-platform installer framework. OpenMRS has lots of implementations on different platforms (Windows, Linux and Mac) and hence I wanted the installer to be cross-platform. At my office, we generally use Windows Installer or NSIS for making installers. But those are only for Windows. These 2 frameworks are so simple and extensible to use that I was thinking if there was something similar and cross-platform, I could make an OpenMRS Installer in an hour. But sadly, that wasn't the case... I tried a variety of installer frameworks, but couldn't find any of them as simple as NSIS or Windows Installer (msi). The following are the installer frameworks I tried working on:

Installer Framework Short Description Problems
1.) Antigen Antigen (Ant Installer Generator) is a tool to take an Ant build script, combine it with a GUI and wrap it up as an executable jar file. Its primary purpose is to create powerful graphical installers from Ant scripts. Couldn't get it to execute ant-calls at lots of places. Didn't work in openSuSE 11.0 due to some incomplete ant configurations. Hasn't been updated in a long time
2.) IzPack IzPack-generated installers require Java. They are simple, efficient and fast to use. Simple executable deployment is best done through IzPack. Isn't very powerful. Good for simple image deployment, but isn't highly configurable and powerful.
3.) OpenInstaller A newer cross-platform installer framework that is completely customizable and written in Java. Glassfish uses this installer framework. Not much documentation. Complex to implement and doesn't look native on all platforms
4.) Netbeans Installer (nbi) A completely customizable and powerful installer framework. Configuration Logic is written in Java and can be used to do anything and everything that Java programs can do. Old documentation. Requires some effort to get up and running with all the scripts.

So finally, I decided to work on using the Netbeans Installer. Netbeans Installer already has components like Tomcat, MySQL, Glassfish, OpenESB and their deployment scripts. And I thought it will simplify my effort... Dmitry Lipin of Sun Microsystems, the lead developer of the NBI team has been of great help over the past weeks and has helped a lot in explaining about nbi... While I was building the installer, 2 other colleagues of mine got interested in OpenMRS and have helped build some parts and want to contribute to OpenMRS code in a larger way!!

I have successfully been able to build an Installer/Uninstaller that can deploy Tomcat/Glassfish, MySQL and the OpenMRS web application on Windows, Linux, OSX, Solaris. The demo data set, JRE/JDK and starting the respective servers are yet to be completed.

Update: The OpenMRS Windows Installer based on Bitrock has been upgraded to install the latest version of OpenMRS. Is it useful for the OpenMRS community to have a cross-platform installer?? Or do the Windows guys only need an Installer ??

Students Review Contest for MySQL & Glassfish

Sun Microsystems has announced a students review contest for MySQL and Glassfish, where students have to develop an application using MySQL and Glassfish. The project has to be part of the java.net website and a review has to be written on MySQL and Glasssfish.

The contest is useful for students who are learning to develop web application and will also help Sun if students get interested in these products. The contest has the following prizes to be won:

  • A chance to win a grand prize of $500 in Visa debit card, and
  • Five chances to win a prize of $250 in Visa debit card

Other than the prizes, students should also be interested in the contest because its a nice learning experience and students will also improve their writing skills by blogging. There is also a certificate that is given to all the winners and its good to show-off you accolades. I won the 2nd prize on the students reviews contest last time and it was an interesting contest to participate.

Chhandomay Mandal manages these student contests and he's very polite and always ready to help. Ask him questions here.

Review: Google Chrome

Today, Google released its open-source browser called Google Chrome to the world, after making us feel in 2006 that it was an April Fool’s Joke. Yesterday, in an announcement, it disclosed the features of Google Chrome and claimed that we require a new browser because the web has changed. As soon as it was released, I downloaded it and here are my observations after using it for the last 4 hrs.

The first thing you notice is that it’s an online installer and still requires ~450Kb (for comparisons: utorrent is half the size and can download the whole world for you!!) . It’s only released for Windows at the moment and will require sometime before its released for Linux. The online download was pretty slow for my connection, but I realized that may be half the internet users were downloading it and that can be daunting even for a biggie like Google.

Finally the downloader finished and I was ready to surf on Google Chrome. First thing you’ll notice that it occupies nearly all available screen space. No menubar with File, Edit and the like!! And there is the Opera like UI with SpeedDial for most visited websites and Search History. Also the Address Bar is pretty efficient with all the quick searching and intelligent suggestions.

chrome-speedial

I was expecting Chrome to be memory hog, but it really is pretty light on the memory usage. With less than 10 tabs open, it surely uses less memory than Opera, Safari and surely Firefox. As the tabs increase Chrome seems to take up as much memory as other browsers. The Browser TaskManager, which can be found when you right click on the open Taskbar or TitleBar is another very useful addition to the browser. But what’s interesting to note that with so many security and stability improvements like separate processes and JavaScript sandbox, Chrome has done an excellent job at keeping the memory usage low. May be if addons are introduced, it’ll screw Chrome as well, but for now it’s doing good!!

Google_Chrome

There aren’t many things to be set in the Options that other browsers don’t have, but the search management was interesting. Since, I am from India, it showed me the popular Indian search engines. Yahoo India, MSN India, Rediff, Guruji were the available search engines and that was interesting because it’s always efficient to have a localized search.

This in my opinion is the most important part for a web browser. Like a phone should be best at voice transmission and quality, a browser should be best at displaying websites accurately and swiftly. Chrome uses Webkit (aka Apple Safari’s Engine) for rendering web pages and I wasn’t expecting many differences from Safari. But I found a few changes between the released version of Safari and Chrome. May be Chrome uses a newer version or something. Chrome scores 76/100 on the ACID3 Web Standards test which isn’t really bad, but I was still expecting 100% as Webkit and Opera have already reached 100% in their development products.

JavaScript performance is super fast. You can look at the benchmarks here. The team from Denmark has done an awesome job and Chrome's JavaScript performance is the best among all the browsers.

I'll write more about it later... but you can read what other people at GigaOm, TechCrunch, TheInq and Gizmodo are saying. Its all over the web and no kidding Google OS is really here to stay!!

Google Chrome's Beats Others at JavaScript Performance

With Google Chrome released, one of its most awesome features is the excellent JavaScript performance. It is a complete new re-write of the JavaScript VM and uses what is called the V8 Engine by the Google developers who worked on the new JavaScript engine. Here is a JavaScript Performance Analysis for developers to look at comparing different browsers.

Google uses a lot of AJAX and the new V8 engine is the king in JavaScript performance done using Dromaeo :

Browser Time (lower the better)
Chrome 0.2.149.27 488.80ms
Firefox 3.0.1 1775.00ms
Opera 9.52 1767.60ms
Safari 3.1.2 2075.00ms

The memory usage of Chrome is also pretty good and the built-in task manager for looking at the memory/CPU usage of tabs is interesting and useful. It can also help in analyzing which tab is creating some kind of menace or using more memory. You can close that tab and get some free memory. This is just an initial preview, but the JavaScript performance is top-notch!!