*** MOVED ***

NOTE: I have merged the contents of this blog with my web-site. I will not be updating this blog any more.

2006-12-27

Utterly Disgusting

It is utterly disgusting that Microsoft so readily bends over backwards to please the immensely greedy folks from the entertainment industry.

For example:

2006-12-25

On The One Hand

On the one hand, a cute baby...

2006-12-21

"LtU Books" In India

There are some books on computer science that I had never heard of until I had started reading "Lambda the Ultimate" (LtU). I found these books being mentioned and recommended in various posts and forum topics on LtU from time to time. As I found out more about these books, I became interested in reading them. Since they were relatively obscure, I had no hopes of finding them here in India. The prospect of having to fork out hefty sums of money for buying the books via something like Amazon.com made me apply the brakes on my normal impulse of buying an interesting book when I come across it.

Imagine my delight then, when I stumbled upon the fact that all of these books had an Indian reprint available at an extremely affordable price. Incidentally, all of these books were originally published by MIT Press and the Indian reprints are published by Prentice-Hall of India.

Here are the "LtU Books" along with the ISBNs of their Indian reprints and the corresponding price:
  1. "Types and Programming Languages" by Benjamin Pierce, ISBN: 81-203-2462-5, 350 rupees.
  2. "Concepts, Techniques, and Models of Computer Programming" by Peter Van Roy and Seif Haridi, ISBN: 81-203-2685-7, 450 rupees.
  3. "How to Design Programs" by Matthias Felleisen, Robert Bruce Findler, Matthew Flatt and Shriram Krishnamurthi, ISBN: 81-203-2461-7, 325 rupees.
  4. "Advanced Topics in Types and Programming Languages" by Benjamin Pierce, ISBN: 81-203-2792-6, 425 rupees.
  5. "The Elements of Computing Systems" by Noam Nisan and Shimon Schocken, ISBN: 81-203-2885-X, 195 rupees.
If you are not able to get these books in a local book store in your city, you can order them directly via the web site of Prentice-Hall of India. If you stay in Bangalore, you can also contact Suman M. (msuman AT phindia DOT com) to obtain these books directly from Prentice-Hall.

2006-12-14

Articles by Dheeraj Sanghi

Dheeraj Sanghi is a professor in the Computer Science and Engineering (CSE) department at IIT Kanpur. Our batch, the CSE class of 1996, studied "Computer Networks" under him and he was an active patron of the Association of Computer Activities (ACA).

Recently I stumbled upon a collection of his articles on various topics, including career counselling for students who want to study CS in India, improvements to the undergraduate programme in IIT Kanpur, views on the recent move by the Indian government to impose quotas in the IITs, etc.

Though I found myself disagreeing with some of his points, I found these articles quite interesting as they touch upon topics that I have been thinking about in recent times.

2006-12-11

Dhoom 2

Go and watch Dhoom 2 if you haven't already. You get to see from two to four hot bodies (depending on your inclination) and some of the best stunts seen in Hindi cinema.

Besides that, try not be disappointed by the script (such as there is) comprising utterly inane dialogues, the plot (such as there is) comprising completely illogical turn of events, the skill of the actors (such as there is) that makes a chiselled wooden statue look more expressive, the fact that the character played by Uday Chopra is not killed off in this film either, the tendency of every actor in this film to walk or run in slow motion, the unnecessarily numerous and forgettable songs (except for the title song), etc.

See also: VikGup's hilarious review of Dhoom 2.

2006-12-05

Bumper Sticker

On the way to work this morning I saw a rather dilapidated car sporting this bumper sticker:

!! CAUTION !!
My Senseless Driving
May Fear You

I found this rather funny in more ways than one.

2006-11-27

FOSS.IN/2006: Impressions

FOSS.IN/2006 is over. This year the event was held in the J. N. Tata Auditorium complex of IISc, Bangalore. This meant that we had much better seating arrangements and acoustics compared to last year, though some of the halls were awfully musty and for some reason the airconditioner in every hall was set to too low a temperature for my comfort. The food was much better than what was there last year and there were enough pure water dispensers to quench everyone's thirst throughout the day every day.

The scale of the event however was much smaller this year compared to last year. It was held for just three days instead of four days as in last year and there were just five simultaneous talks through the day instead of six as in last year. While many of the American hackers chose to skip the event this year due to its unfortunate overlap with the Thanksgiving weekend, I don't know what would explain the much lower turnout of Indian delegates and exhibitors.

I didn't find that many interesting talks this year so it was a bit depressing for me. In addition, there were many a glaring error in a couple of talks that I attended. Among the talks that I did like were the ones by Christof Wittig and Russell Nelson on the first day, the one by Aaron Seigo on the second day and the one by Tim Pritlove on the third day.

In a talk on OpenAlchemy, I asked why anyone in India should buy an Amida Simputer when it has a bulky form factor and is more expensive than a Palm Tungsten E2 which at first blush seems to have many a desirable feature and looks far more polished. Another member of the audience asked where it stands now that the OLPC project is here. I wasn't happy with the answers provided for either of these questions.

2006-11-17

New York, Philadelphia and Boston

In the last week of my recent US trip, Anusha and I tried to cover the cities of Philadelphia, New York and Boston. When the time for travelling between these cities is factored in, we had almost no time to see any of these cities properly. The weird policy of the hotels in the US to have check-in after 4 PM and check-out by 12 noon made the problem worse. It also didn't help that the sun used to set around 5 PM.

We spent about 2 and a half days in New York while staying in New Jersey and we still managed to visit five families of our relatives, meet Saikat and Kalpana and see some of the most famous tourist attractions in New York.

Hotel accommodation in New York, especially Manhattan, seems insanely expensive, even for the hotels with only the most basic of amenities. Ditto for car rentals and parking charges. Fortunately for us, decent hotels in New Jersey are somewhat more affordable and there are excellent public transportation options for shuttling between NJ and NYC. As a matter of fact, we stayed in a hotel in Jersey City that was a five minute walk from the Journal Square PATH train station. PATH trains were numerous and frequent throughout the day and took us into the heart of Manhattan in 20 minutes. Within New York, the excellent subway system made travelling within the city relatively painless.

Visiting the Statue of Liberty and the Empire State Building took half a day each because of the number of tourists and the elaborate security procedures. The view of New York City from atop the Empire State Building was very nice and the audio tour by "Tony, the cab driver" was quite useful for an utter newbie to the city. By the way, I didn't know that the Statue of Liberty was made out of copper sheets and the green colour was due to the usual patination of copper.


12x Optical Zoom is Cool

Central Park was quite impressive with its lush greenery and peace right in the middle of Manhattan. Actually it was amazing just how many parks there were in Manhattan itself. The Grand Central Station was simply awesome for a train station. The New York Public Library was fairly impressive as well. Times Square in the night was just as they show on TV and in the movies but for some reason it had just a lukewarm effect on me. The site where the twin towers of the WTC stood seemed big and eerily empty. Walking on the Brooklyn Bridge was a charming experience. It was nice walking around in Manhattan soaking in the sights of the city and gaping at the numerous skyscrapers.

We didn't get time to watch a Broadway show or visit any of the famous museums. In a city with more than 13,000 restaurants offering the most varied cuisines in the world, we were mostly so pressed for time that we used to just grab a quick bite in a fast food joint. Some day I hope to come back to this city and stay for at least a week or more.

We were not able to see much in Philadelphia due to a lack of time and Boston was only slightly better. In Boston, our misfortune was compounded by the long-term renovations being carried out at the sites of the Boston Tea Party and the Bunker Hill Monument. As if that was not enough, it was also raining persistently throughout the first half of the day we had set aside to see the city. We still managed to follow some of the Freedom Trail, see the USS Constitution and explore Quincy Market, Faneuil Hall, etc.

2006-11-15

Las Vegas

Anusha joined me on the second weekend of my recent US trip for a visit to Las Vegas along with VikGup and Pooja, who took turns to drive all the way. It took us about 10 hours each way with a break or two and that meant that we had just a little over 24 hours to spend in Vegas.

The glitz and glamour of Vegas was unlike anything I had seen before. It was particularly striking after having driven through hours of arid and dreary landscape. The sheer display of wealth and beauty has to be seen to be appreciated. It also becomes very obvious, very fast, how this city earned the moniker "Sin City".

We hopped from hotel to hotel checking out the attractions on display. It was amazing to see so much money and effort spent on recreating the landmarks of Paris, New York, Venice, etc. We didn't gamble much and I even managed to make a tiny profit. One of the most memorable part of this trip for me was watching the show "O" by Cirque du Soleil at The Bellagio.

Anusha checking out a slot machine

2006-11-08

"Canon Rock" by Jeong-Hyun Lim ("Funtwo")

It has apparently been a rage on the Internet for some time now, but only recently have I come across the cover version of "Canon Rock" played by "Funtwo". The original version was arranged and played by "JerryC".

2006-10-23

Fry's

Ryan and I went to the Fry's store in Sunnyvale yesterday. Our original plan was to spend about half an hour there, move on to the DSW store in Milpitas and then to San Francisco - we ended up spending about 6 hours just in Fry's!

To a bumpkin coming from India, Fry's is just incredibly big and has an amazing variety of items. The very idea of being able to take a shopping cart through aisles upon aisles of hardware components and picking up just the right components to build my dream computer would have been enough to make me wet my pants in my days as an avid gamer. I am sure that electronics enthusiasts back home would have a similar feeling if they see how easily they can get all sorts of electronic components and related hardware in this store. Awesome!

If I were younger, I would have filled my cart with all sorts of cool stuff, including the Lego Mindstorms NXT robotics kit. I did not because I realise that I would simply not have the time to play with all that cool stuff and it would therefore just be a waste of money. Sad.

2006-10-22

San Francisco

I spent the first weekend of my current trip exploring the city of San Francisco, first with VikGup and Pooja and then with Ananth and Surabhi. I will also be going to the city almost every day this weekend and the whole of next week, but I do not expect to have much time that I can spend exploring the city (which is a shame since I have really liked what I have seen of this city so far).

One of the first things that I noticed about this city was its diversity - there are so many people of so many ethnicities that it seems to be about as cosmopolitan as any city can possibly get. The next thing I noticed was the ruckus created by motorcycle riders (mostly riding Harley-Davidsons) almost everywhere. Finally, I really didn't expect the city to be so small!

I was with VikGup and Pooja for some time on the first day and then I walked around The Embarcadero, visited Fisherman's Wharf, Market Street, Chinatown, etc.

The next day with Ananth and Surabhi, I saw the Golden Gate bridge, visited Haight-Ashbury and the Amoeba store, ate at Massawa (an Ethiopian restaurant) on Haight street, indulged in the creations of Ghiradelli, went up the steep roads of Russian Hill and down the hairpin bends of Lombard Street, etc.

A charming city. I wish I were able to explore it properly.

US of A

I have been in the US of A (Redwood City, California) for a little over two weeks now.

This is only my second visit to the US. I was in Edison (New Jersey) for a week about five years ago. For a number of reasons, I was miserable during my stay the last time around. I was suffering from jet lag for much of my stay - I wasn't able to sleep till about 4AM every day, but then had to get up by 7AM to get ready and go to work only to find myself groggy throughout the day. I used to accumulate so much static electricity so rapidly that I used to be shocked by touching almost anything - door knobs, car doors, coffee machines, humans, etc. - and would remain jumpy throughout the day. Even though the hotel that I stayed in was close to my workplace, I couldn't actually walk there and had to always depend on someone to pick me up, take me out for lunch and dinner and drop me back. But for some of my extremely helpful and accommodating colleagues, I would have had a terrible time. Since I stayed for such a short time, I also didn't get to go around and see places.

This time it's much better. My jet lag was less severe and I got over it pretty quickly. The weather is warm and really pleasant most of the time. The hotel that I stay in is a bit further from my workplace compared to the last visit, but there are very nice pedestrian sidewalks and
the path is surrounded by beautiful grass, trees and lakes. There is a supermarket, a bunch of restaurants and other shops very close to the hotel (but for some strange reason, every restaurant and shop in this area closes by 8:30PM - only the supermarket remains open till 11PM). There is good public transportation available here and the nearest Caltrain station (San Carlos) is just about a mile from my hotel. Finally, many of my friends live in this nook of the world, though I've only been able to meet Ananth, Yumpee and VikGup so far.

On the weekends, I've been able to see San Francisco and Las Vegas but both of them merit separate posts.

2006-09-27

ICFPC 2006: Epilogue

The results of the ICFP contest for 2006 are now available. "Team Smartass" came first, followed by "kuma-" and "You Can't Spell Awesome Without ASM" in the second and third places respectively. Amazingly, the lone hacker "Witrala" was able to take the fifth place. Congratulations!

There is also a a video of the presentation by the contest's organisers at ICFP 2006. It is quite shaky, there are audio and video synchronisation problems and there is a guy sitting near the camera who gets tickled by almost everything into laughing out loud, but it is still worth a watch, especially for those who participated in the contest or those who want to know just how the organisers created the task.

This year's contest has proved to be so popular that the organisers have created a separate site called boundvariable.org dedicated to the "Cult of the Bound Variable".

An interesting bit about this year's contest was that the teams in the first and the third places were both from Google. Another interesting bit is that the individual members of these teams are also ranked very high on TopCoder and have been toppers in various contests organised by TopCoder. "Team Smartass" comprised Christopher Hendrie (ChristopherH), Derek Kisman (SnapDragon), Ambrose Feinstein (ambrose) and Daniel Wright (dmwright). "You Can't Spell Awesome Without ASM" comprised John Dethridge (John Dethridge), Ralph Furmaniak (RalphFurmaniak), Tomasz Czajka (tomek) and Reid Barton (reid).

Update (2006-10-22): Yumpee has pointed me to the ICFP 2006 paper (PDF) written by the organisers.

2006-09-26

Fullmetal Alchemist

I generally like animé, but I am not into it the way VikGup is, for example. About the only series I used to watch regularly was Dragon Ball Z (DBZ), before Cartoon Network India abruptly and very irritatingly pulled it off the air just as it was near the final few episodes. I liked the overall story in DBZ, but I felt the episodes and the fights were unnecessarily long and dragged-out, really testing one's patience (it reminded me of Ramanand Sagar's TV series "Ramayana"). I also liked Animatrix a lot. I have watched parts of other animé series, but I have never felt compelled to watch an entire series from the beginning to the end.

I am not a fan of the way most serious animé suddenly switches to "silly mode" in the middle of a scene, with characters swinging their limbs about wildly and screaming for no good reason, the drawing degrading in quality with quivering outlines - it just ruins the whole experience for me. I also find a bit odd the technique of showing an essentially still frame and then moving the camera about - I realise that the animators want to save effort and that it is a commonly-used technique elsewhere, but it seems to be used a lot more often in animé and I wish they didn't do it. Finally, the English dubbing is almost always terrible and I wish I could just see them in the original Japanese with English subtitles (I believe the DVD releases allow you to do that). All this aside, I must admit that many of the more popular animé series are beautifully drawn and have an overall story that is so fantastically different from anything else that one generally gets to see.

When I read Stevey Yegge's blog post on animé, I felt an urge to check out some of the animé series that he recommends. As luck would have it, Animax India has been showing some of the animé series that he highly recommends and on a whim I decided to check out Fullmetal Alchemist.

I am not disappointed at all - this is a wonderful series. It does switch to "silly mode" some times, but the rest of it is so good that I can live with that. The art is awesome, the story is intriguing, the music is nice and the story actually moves forward in each episode. No wonder many people have rated it one of the best animé of all time.

By the way, by the time I started watching the series, the episodes being shown were from the last one-third of the series so I didn't quite follow some of the things. Fortunately, Animax started showing the whole series from the beginning on weekends in a "catch-up marathon", with eight episodes shown back-to-back on every day of the weekend. In the evening on weekends they also show five episodes back-to-back to allow you to catch-up with the regular episodes that were shown during the week. It is a bit exhausting and my wife and sister think that I have gone crazy.

I am really looking forward to watching the concluding episodes that will be shown during this week and the next. I am also looking forward to watching the movie.

2006-09-19

"The Vietnam of Computer Science"

Via reddit.com, "The Vietnam of Computer Science":

"Although it may seem trite to say it, Object/Relational Mapping is the Vietnam of Computer Science. It represents a quagmire which starts well, gets more complicated as time passes, and before long entraps its users in a commitment that has no clear demarcation point, no clear win conditions, and no clear exit strategy."

A nice albeit verbose article on why using Object/Relational Mapping to store objects in relational database systems sounds like a good idea at first but then becomes a quagmire once you start trying to resolve more and more of the inherent differences between the two approaches.

2006-09-15

Terminal Sickness

I have a simple requirement: I want my programme to be able to spawn another programme on the same machine and talk to it using the simplest possible means of communication, that is, via the spawned programme's standard input and output streams.

The driving programme is written in C and the spawned programme could have been written in any programming language (hence the need for using as simple a form of communication as possible). The messages exchanged between the programmes are terminated by newline characters.

This should have been a relatively simple task with code somewhat like the following (error-handling has been omitted for clarity):

/* File descriptors for pipes connecting driver and inferior
processes. */
int drv2inf[2], inf2drv[2];

/* Create communication pipes. */
pipe (drv2inf); pipe (inf2drv);

if (fork () == 0) {
/* In child process - close "other" ends of pipes first. */
close (drv2inf[1]); close (inf2drv[0]);

/* Redirect stdin and stdout. */
close (0); dup (drv2inf[0]); close (drv2inf[0]);
close (1); dup (inf2drv[1]); close (inf2drv[1]);

/* Spawn inferior process - should never return. */
char *args[] = { prog, NULL};
execv (prog, args);
} else {
/* In parent process - close "other" ends of pipes first. */
close (drv2inf[0]); close (inf2drv[1]);
}

However, running this with a test programme (written in C) revealed a problem: messages sent by the spawned programme were not reaching the driving programme!

The reason is that stdout is normally "line-buffered" - i.e. output is buffered till either the buffer becomes full or till a newline character is encountered. When stdout is not connected to a terminal however (for example, when output is redirected to a file), it becomes "block-buffered" - i.e. output is buffered till the buffer becomes full. Of course, you can force the output buffer to be flushed out using fflush() at any time. This behaviour of the C runtime is a reasonable tradeoff that seeks to optimise throughput and response under different conditions. In my case the C runtime determined that stdout was not connected to a terminal and therefore should be block-buffered. The messages sent by the spawned process were therefore still sitting in its output buffer while the driving process waited to hear from it.

My knee-jerk reaction was to insert a call to setvbuf() with a mode of _IOLBF just before the call to execv() in order to force a line-buffered mode for the spawned process. Of course, this does not work for the simple reason that the C runtime is re-initialised after the call to execv().

A possible solution is to mandate that the spawned programme force a line-buffered mode for stdout using something like setvbuf(). Another solution is to mandate that the spawned programme always use the equivalent of fflush() to flush its output buffers after every message. However, these just work around the problem rather than solving it. I also do not want to place unnecessary restrictions on spawned programmes.

So it seems the only solution left is to use a pseudo terminal to fool the spawned programme's runtime into thinking that it is attached to a terminal. A glance through the sample code given in my copy of Stevens's "Advanced Programming in the UNIX Environment" reveals that some ugly code is needed to make it work properly. It also makes my programme even less portable than it currently is. I am therefore a bit loath to take this approach.

Does anyone know of a better solution to this problem?

Update (2006-09-16): Thanks to all who responded. Using a pseudo terminal solved my problem. The forkpty() function from libutil provided by the GNU C Library (thank you Scott) conveniently wraps everything I need into a single function. The only problem is that it also redirects stderr to the newly-created pseudo terminal and this robs the spawned programme of a simple method of debugging. To work around this issue, I had to save the stderr stream using a dup() before calling forkpty() and then restore it using a dup2() in the child process.

One of the problems with using a pseudo terminal that initially stumped me was the fact that the spawned programme seemed to send the driver programme all the messages it was sent by the latter in addition to sending messages of its own. It took me a while to realise that this was because of terminal echo. Switching terminal echo off resolved this problem.

Update (2007-10-18): Here is the relevant portion of the programme that finally worked for me:

#include <stdio.h>
#include <stdlib.h>

#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <termios.h>
#include <pty.h>

/* Spawns a process with redirected standard input and output
streams. ARGV is the set of arguments for the process,
terminated by a NULL element. The first element of ARGV
should be the command to invoke the process.
Returns a file descriptor that can be used to communicate
with the process. */
int
spawn (char *argv[]) {
int ret_fd = -1;

/* Find out if the intended programme really exists and
is accessible. */
struct stat stat_buf;
if (stat (argv[0], &stat_buf) != 0) {
perror ("ERROR accessing programme");
return -1;
}

/* Save the standard error stream. */
int saved_stderr = dup (STDERR_FILENO);
if (saved_stderr < 0) {
perror ("ERROR saving old STDERR");
return -1;
}

/* Create a pseudo terminal and fork a process attached
to it. */
pid_t pid = forkpty (&ret_fd, NULL, NULL, NULL);
if (pid == 0) {
/* Inside the child process. */

/* Ensure that terminal echo is switched off so that we
do not get back from the spawned process the same
messages that we have sent it. */
struct termios orig_termios;
if (tcgetattr (STDIN_FILENO, &orig_termios) < 0) {
perror ("ERROR getting current terminal's attributes");
return -1;
}

orig_termios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
orig_termios.c_oflag &= ~(ONLCR);

if (tcsetattr (STDIN_FILENO, TCSANOW, &orig_termios) < 0) {
perror ("ERROR setting current terminal's attributes");
return -1;
}


/* Restore stderr. */
if (dup2 (saved_stderr, STDERR_FILENO) < 0) {
perror ("ERROR restoring STDERR");
return -1;
}

/* Now spawn the intended programme. */
if (execv (argv[0], argv)) {
/* execv() should not return. */
perror ("ERROR spawning programme");
return -1;
}
} else if (pid < 0) {
perror ("ERROR spawning programme");
return -1;
} else {
close (saved_stderr);
}

return ret_fd;
}

2006-09-10

Crikey

Germaine Greer in The Guardian on Steve Irwin:
"The only creatures he couldn't dominate were parrots. A parrot once did its best to rip his nose off his face. Parrots are a lot smarter than crocodiles."

[...]

"What Irwin never seemed to understand was that animals need space. The one lesson any conservationist must labour to drive home is that habitat loss is the principal cause of species loss. There was no habitat, no matter how fragile or finely balanced, that Irwin hesitated to barge into, trumpeting his wonder and amazement to the skies. There was not an animal he was not prepared to manhandle. Every creature he brandished at the camera was in distress."

This was the seemingly sole voice of reason among the glowing obituaries all over the place hailing the "Crocodile Hunter" as a hero and a conservationist of wild life.

2006-09-09

Exercise

I'm not a fitness freak but I do believe in the old adage that a healthy body houses a healthy mind. Consequently, I had decided early on in my life to try to remain as fit as is reasonably possible. Unfortunately for me, I have not consistently implemented this resolution over the years with the natural result that I had become lethargic, easily tired and had gained unseemly tyres of fat on my person. I have been trying to rectify matters over the last few months and it seems to be paying off, slowly but surely.

Back in college there was a time when I used to jog in the mornings, swim in the afternoons and play football in the evenings, though I took on the latter two activities more for fun than for improving fitness as such. After leaving college and taking up a job, I tried to jog regularly in the mornings but gave up after a couple of months or so. Without jogging partners from my college days like Pranjal and Subra to goad me, it required too much will power and discipline to refuse the warm embrace of sleep and brave the cold morning air every day. As a wit once remarked, the toughest distance you have to cover while jogging is the stretch between your bed and the floor. To keep myself from putting on excess weight, I tried to regulate my diet a bit. However, that can only help so much when your entire day is spent sitting on a chair at your workplace and your entire night is spent either sitting on a sofa or lying on a bed. Before I realised it, ten years had passed and I had become an embarrassingly unfit image of my former self, advancement of age notwithstanding.

So I have been forcing myself over the last few months to go to bed relatively early (10 PM) and get up and go for a jog, or even a brisk walk, early in the morning. It was difficult at first and I was very irregular but it has now become easier - I wake up by 6 AM without the need for an alarm and am able to convince myself to get out of bed.

I prefer running through the streets of the city in a single long loop and getting a varied view rather than doing monotonous laps in a park or a stadium or staying at one place on a treadmill. Unfortunately for me, it turns out that there are an alarming number of vehicles on the streets even at 6 AM in the morning and spewing noxious fumes and that there are a large number of stray dogs which sometimes bark at you, sometimes run after you and sometimes leave their poop behind for you to watch out. The footpaths are not continuous or even and the roads have oddly parked vehicles or idiots driving the wrong way. The parks nearby are a bit too crowded for me to have any hope for a decent pace of jogging. The playgrounds in the neighbourhood are either too muddy or filled with children, not to mention stray dogs.

I had therefore switched over rather reluctantly to running on a treadmill. Fortunately for me, I live in an apartment complex that has a fairly decent gymnasium. I found out that running on a treadmill is not as bad as I had feared and is in fact much better in several ways. For one, the surface is not as hard as that of a road or a footpath so it feels much better to run on. More importantly, it allows me to properly warm up, maintain a steady jogging speed for a while and then properly cool down. I can easily control the effort expended by varying the speed, the slope and the duration. I can vary the programme to accommodate any constraints of time I might have. The other equipments available in the gymnasium also allow me to exercise other parts of my body. There are also some other benefits of working out in a gymnasium that cannot be described publicly without putting one's marital life into jeopardy. ;-)

One of the pleasantly surprising facts of working out is that it actually leaves me energetic and enthusiastic, rather than tired and achy, for the rest of the day. I feel much better than before and I hope I am able to maintain this regimen.

2006-09-08

Good Bye Advogato!

Advogato is going offline.

I feel a bit sad about it even though I had stopped updating my Advogato diary and have been using Blogger for blogging for the last three months. After all, Advogato is where I started blogging regularly.

mibus provides a nice tip: You can access all your Advogato diary entries in a convenient XML format by appending "diary.xml" to your normal diary URL. For example:

http://www.advogato.org/person/rmathew/diary.xml

There is a "Planet (Former) Advogato" for aggregating the blogs of all those who used to blog on Advogato but have moved elsewhere for one reason or the other.

2006-09-07

Expensive Conferences

I like to pretend that I am interested in compiler construction techniques. I was therefore quite interested in attending the New Horizons in Compilers (mirror) workshop that will be held as a part of HiPC 2006 right here in IISc Bangalore. Unfortunately, it turns out that you have to register for the entire conference to be able to attend this workshop. The really awful part is that I would have to part with 22,500 rupees ($500) to be able to do that. There is no way that I am ever going to shell out that kind of money for something like this.

Apparently this is supposed to be the "reduced rate" for Indian participants who are not from academia, government organisations or three-four letter organisations. Even for ACM/IEEE/IFIP members, it is still 16,900 rupees ($375) and that is still a lot of money in this part of the world for this kind of an event. It is as if they are making an active attempt to keep everyone else out. I did ask the "registration chair" and the workshop organisers for a better option but apparently there is none.

What a shame!

2006-09-06

Where is The Purple Dragon Book?

The "second" edition of the Dragon Book (a.k.a. "Compilers: Principles, Techniques and Tools" by Alfred Aho and others) has already been delayed a lot, considering that the previous edition was published twenty years ago in 1986 and the new edition was supposed to be published "soon" years ago. The final publishing date was supposed to be 31st August 2006 and the corresponding Amazon.com page and the Addison-Wesley page continue to stick to the same date as of this writing and yet proclaim the title to be unavailable. Jeffrey Ullman says that the book is finally done and that they handed it over to the publisher at the end of June 2006, so I wonder what is causing all these delays and whether the wait would be worth it. Note that an online preview of some of the revised as well as newly-added chapters is still available, though the site uses an awful amount of Flash, JavaScript and pop-ups for some weird reason.

I put "second" in quotes since the publisher says that this is the second edition, though coming after the Green Dragon Book and the Red Dragon Book, I think this should be called the third edition of the book. However, I do realise that there was a change in the title of the book and it was thoroughly revised when it was published as the Red Dragon Book, so this is just nitpicking on my part. It has already been nicknamed the Purple Dragon Book based on its cover, continuing the convention for giving nicknames to its predecessors.

I read parts of the Red Dragon Book when I took the Compilers course in my college about twelve years ago. It was a bit boring (as are almost all textbooks I have ever read), but it was the only book I could lay my hands on that covered bits of everything about compiler construction. Even to this day, 20 years after it was published, it still seems to be a recommended book if you want to know about the basics of compiler construction. However, it is acknowledged to be terribly out-of-date with the current techniques, so a major revision was long overdue.

I have been meaning to brush up on the fundamentals of compiler construction techniques for several years now, especially since the time I was introduced to the development of GCC, but my excuse was that I wanted to postpone it till the time the new edition of the Dragon Book becomes available (which was always marked to be released "any time now"). Now that the Purple Dragon Book would become available "soon", my excuse is that I would at least wait for the second printing so that all the readily-apparent errors are corrected and I don't have to read the book with a thick errata in hand. I would also wait for the low-priced Indian edition to become available since the international editions are atrociously priced in my opinion.

Yes, I do make up really silly excuses for what is ultimately procrastination driven by plain old sloth.

Update (2006-06-07): As luck would have it, just a day after I write about the unavailability of this book, both Amazon.com and Addison-Wesley now show it as in-stock and ready for shipping.

2006-09-04

"If You Come Today"

"If you come today, it's too early. If you come tomorrow, it's too late. You pick the time."

Sriram pointed out a video of the (English) song "If You Come Today" sung by and featuring Rajkumar. The lyrics of the song are rather confounding, but my favourite parts are the "Tick, Tick, Tick, Tick..." and the "DOHLING!".

2006-08-28

A Bold Question

Does anyone know why comics writers put one or two words in every sentence in every dialogue in bold typeface?

For example, "Watchmen" is perfect in every other way except for this flaw. I tend to translate bold typeface as indicating an emphasis on a word or a phrase, so it is rather jarring to read dialogues mouthed by characters in comics.

Why do they do this?

2006-08-18

RMS, GPLv3 and Bangalore

Richard Stallman will be talking about "Free Software: Current Status and Challenges" at 11 AM in the Faculty Hall in IISc Bangalore tomorrow (Saturday, 19th August 2006). I came to know of this event just this afternoon and I understand that this is too short a notice, but I hope to meet some of the fellow Free Software enthusiasts in Bangalore.

On a related note, Bangalore will also be hosting the Fourth International Conference on GPLv3 on the 23rd and 24th August 2006, this time in IIM-B. Both Richard Stallman and Eben Moglen will be presenting in this event. Since this falls in the middle of a work week (Wednesday/Thursday), I will have to skip it.

2006-08-17

Good Math, Bad Math

I came to know of Mark Chu-Carroll's "Good Math, Bad Math" blog via a post in "Programming Musings", the blog of José Antonio Ortega Ruiz. Mark writes mostly about mathematics, the theoretical foundations of programming, debunking bad use of mathematics in popular and not-so-popular media, etc.

I find many of Mark's articles very interesting to read, though many others go way over the top of my head. Some of his recent articles that I found really interesting include one that shows how absurd arithmetic with Roman numerals can be, one on Poincaré Conjecture, some in the "Friday Pathological Programming Language" series, one on zero, one on i, one on e, one on φ, one on Ω, one on Ï€, one on continued fractions, etc. The old home for the GM/BM blog contains many more interesting and insightful articles on math and programming theory. What an amazing guy!

Highly recommended.

2006-08-14

Balancing Acts

You are given 8 billiards balls, numbered 1 to 8, identical in shape and size. All but one weigh exactly the same. The odd ball is either heavier or lighter than the others. Using just three weighings on an ordinary two-pan balance, find the odd ball out as well as whether it is heavier or lighter than the others.

If you solve the previous puzzle, solve the same problem for 12 billiards balls (instead of 8) while keeping the maximum weighings to just three. Yes, there is a solution for this puzzle - if you give up, you can find the solution here.

For the first puzzle (with just 8 billiards balls), here is my solution (obfuscated using rot-13):
  1. Xrrc onyyf ahzorerq 1, 2 naq 3 ba bar cna naq 4, 5 naq 6 ba gur bgure.
  2. Vs gurl onynapr, gurl ner nyy abezny naq bar bs 7 naq 8 vf gur bqq onyy. Jrvtu 7 ntnvafg 1.
  3. Vs gurl onynapr, 8 vf gur bqq onyy naq lbh pna svaq vgf bqqvgl ol jrvtuvat vg ntnvafg 1.
  4. Vs gurl qba'g onynapr, 7 vf gur bqq onyy naq lbh jvyy vzzrqvngryl xabj vs vg vf urnivre be yvtugre guna gur bguref.
  5. Vs gur onyyf qba'g onynapr va fgrc #1, bar cna jvyy tb qbja. Jvgubhg ybff bs trarenyvgl, nffhzr guvf vf gur bar pbagnvavat 1, 2 naq 3. Rvgure bar bs 1, 2 naq 3 vf urnivre guna gur bguref be bar bs 4, 5 naq 6 vf yvtugre guna gur bguref.
  6. Xrrc 1 naq 5 ba bar cna naq 4 naq 2 ba gur bgure. Xrrc 3 naq 6 nfvqr.
  7. Vs gurl onynapr, bar bs 3 naq 6 vf gur bqq onyy. Sebz fgrc #5, jr pna pbapyhqr gung rvgure 3 vf urnivre guna gur bguref be 6 vf yvtugre guna gur bguref. Jrvtu 3 ntnvafg 1.
  8. Vs gurl onynapr, 6 vf gur bqq onyy naq vf yvtugre guna gur bguref.
  9. Vs gurl qba'g onynapr, 3 vf gur bqq onyy naq vf urnivre guna gur bguref.
  10. Vs gur onyyf qba'g onynapr va fgrc #6, rvgure gur cna jvgu 1 naq 5 jvyy tb qbja be gur cna jvgu 4 naq 2 jvyy tb qbja.
  11. Vs gur cna jvgu 1 naq 5 tbrf qbja, sebz fgrc #5 jr pna pbapyhqr guna rvgure 1 vf gur bqq bar bhg naq vf urnivre guna gur bguref be 4 vf gur bqq bar bhg naq vf yvtugre guna gur bguref.
  12. Jrvtu 1 ntnvafg 8. Vs gurl onynapr, 4 vf gur bqq bar bhg naq vf yvtugre guna gur bguref. Vs gurl qba'g, 1 vf gur bqq bar bhg naq vf urnivre guna gur bguref.
  13. Vs gur cna jvgu 4 naq 2 tbrf qbja va fgrc #10, sebz fgrc #5 jr pna pbapyhqr gung rvgure 2 vf gur bqq bar bhg naq vf urnivre guna gur bguref be 5 vf gur bqq bar bhg naq vf yvtugre guna gur bguref.
  14. Jrvtu 2 ntnvafg 8. Vs gurl onynapr, 5 vf gur bqq bar bhg naq vf yvtugre guna gur bguref. Vs gurl qba'g, 2 vf gur bqq bar bhg naq vf urnivre guna gur bguref.
  15. Va fgrc #5, vs 4, 5 naq 6 tb qbja, pneel bhg gur erznvavat fgrcf ol fjnccvat 1, 2 naq 3 jvgu 4, 5 naq 6 erfcrpgviryl.
I confess that I had to finally give up while trying to solve the 12-ball variation in the second puzzle.

2006-08-10

Lost Books on Computer Programming

I am not into old books on computers the way Graydon seems to be, but I still feel sad that the current generation of programmers will most likely never get exposed to some of the great books on computer programming that I was able to read when I was young.

At least here in Bangalore, it is almost impossible to buy these books from a bookshop unless they have either retained very old stock or are selling second-hand books. For example, here are a few books that seem to be very difficult to buy these days in Bangalore:
  1. "The Elements of Programming Style", Brian Kernighan and P. J. Plauger.
  2. "Algorithms + Data Structures = Programs", Niklaus Wirth.
  3. "A Discipline of Programming", Edsger Dijkstra.
  4. "The Science of Programming", David Gries.
  5. "Communicating Sequential Processes", C. A. R. Hoare.
  6. "How to Solve it by Computer", R. G. Dromey.
  7. "Microprocessors: A Programmer's View", Robert B. K. Dewar and Matthew Smosna.
(I am sure I have not listed a lot of other interesting and important books here, but these are the names that readily spring to my mind.)

Of these, I have only been able to buy Dromey's book so far. In my opinion, it is one of the most under-appreciated books in computer science and deserves to be read by every novice programmer. It is a perfect complement to the usual textbooks for a Data Structures and Algorithms course.

A kind soul has scanned in the pages from "A Discipline of Programming" and made them freely available to everyone. The electronic version of "Communicating Sequential Processes" is now freely available for download. But I still wish I had these books "for real".

By the way, Robert Dewar hopes to produce an updated version of "Microprocessors: A Programmer's View" sometime soon.

Alarmingly, some relatively recent books are also becoming difficult to find these days. For example:
  1. "Programming Pearls", Jon Bentley.
  2. "The Practice of Programming", Brian Kernighan and Rob Pike.
I also note rather sadly that the "XYZ Unleashed" and "Learn ABC in 3 Days" type books are still going strong even after almost a decade.

Thankfully, the "The Art of Computer Programming" (TAOCP) series by Donald Knuth is still easily available. "Structure and Interpretation of Computer Programs" (SICP) by Harold Abelson, Gerald Jay Sussman and Julie Sussman is also visible in bookshops from time to time.

I think the strong sales of TAOCP are more due to the "classic book" effect than anything else. To quote Mark Twain, "A classic is a book that everyone wants to have read but no one wants to read". If there are people who have actually read TAOCP, they seem to have been rather successful at avoiding to meet me. To quote Bill Gates, "If you have read The Art of Computer Programming from cover to cover, send me your resume!".

2006-08-07

The Suez Crisis and The IBM PC

"Those who cannot remember the past are condemned to repeat it."

A recent issue of The Economist featured the article "An Affair to Remember" about the Suez crisis (also known as the Sinai War) of 50 years ago. I found it to be a very interesting read. It provides some great insights into the events precipitating the formation of the European Union, the establishment of the US and the Soviet Union as the only superpowers, the reasons for the different way that the British and the French view the US, etc. I also found it a bit surprising how the then British prime minister Anthony Eden and his foreign secretary blatantly lied to the House of Commons about the sinister collusion between Britain, France and Israel that led to the war.

In the light of the recent events, it is amusing to find out that at that time the US actually went via the UN to put a stop to this uncalled-for agression by the Israelis, the British and the French against the Egyptians. It was apparently also the last time that the US actually acted against Israel while intervening in a war.

How times change.

The same issue of The Economist also featured the article "Getting Personal" about the 25th anniversary of the introduction of the IBM PC. The first IBM PC was apparently priced at USD 1,565, had 16K of RAM, used audio cassettes for storage (a floppy drive was optional) and featured “green phosphor characters for reading comfort” (i.e. text-only, no graphics). It wasn't until Lotus 1-2-3 was introduced about 1.5 years later that the PC really took off. These days you are overwhelmingly more likely to see a PC than an Apple Macintosh or any other kind of personal computer.

I first got to work on an (8086-based) IBM PC in 1990. It struck me as rather ugly and severely lacking. I was used to the excellent BBC Micro and the primitive CGA display of the IBM PC and the PC speaker were nothing compared to what was available on the Beeb. As a novice programmer, it was also very irritating to find how different BASICA was from BBC BASIC. All the "VDU" (graphics) and "ENVELOPE" (sound) tricks I had learnt on the Beeb were also useless on the PC.

It was not until I got to work on the 80386-based IBM PCs and play Prince of Persia and Wolfenstein 3D that I really began to enjoy working on the PC. Borland's Turbo Pascal and Turbo C/C++ were excellent tools that made programming on the PC much easier. After the advent of Linux, there was no question about what my first personal computer was going to be.

2006-08-04

Another River Crossing Puzzle

Most of us would have seen the standard river crossing puzzle. However, Prasadini recently sent me another river crossing puzzle (Flash animation) that I think is far more challenging.

A father and his two sons, a mother and her two daughters, a thief and a policeman are on one side of a river. There is a boat by the river bank, but it can only take two people at a time. Only the father, the mother and the policeman know how to operate the boat. The father can not be with any of the girls without their mother around. The mother can not be with any of the boys without their father around. The thief can not be with anyone else without the policeman around. How can you get everyone across to the other side of the river?

Start the game by clicking on the big round blue button. Click on a person to get him or her on or off the boat. Click on the levers to get the boat to move.

It took me a fair bit of time to crack it and here is my solution (obfuscated using rot-13):
  1. Gur Guvrs naq gur Cbyvprzna pebff bire.
  2. Gur Cbyvprzna pbzrf onpx (Gur Guvrs qbrf abg eha njnl jura yrsg nybar!).
  3. Gur Cbyvprzna naq n obl pebff bire.
  4. Gur Cbyvprzna naq gur Guvrs pbzr onpx.
  5. Gur Sngure naq gur bgure obl pebff bire.
  6. Gur Sngure pbzrf onpx.
  7. Gur Sngure naq gur Zbgure pebff bire.
  8. Gur Zbgure pbzrf onpx.
  9. Gur Guvrs naq gur Cbyvprzna pebff bire.
  10. Gur Sngure pbzrf onpx.
  11. Gur Sngure naq gur Zbgure pebff bire.
  12. Gur Zbgure pbzrf onpx.
  13. Gur Zbgure naq n qnhtugre pebff bire.
  14. Gur Guvrs naq gur Cbyvprzna pbzr onpx.
  15. Gur Cbyvprzna naq gur bgure qnhtugre pebff bire.
  16. Gur Cbyvprzna pbzrf onpx.
  17. Gur Cbyvprzna naq gur Guvrs pebff bire.
See if you can come up with a better solution.

2006-08-03

Optimising Linker Load Times

Last week's LWN.net Weekly Edition had a nice article on optimising linker load times by John Richard Moser. It was based on some recent features added to the linker in GNU binutils. It explains the kind of things that most of us never bother to learn about, but which can affect the loading times of our applications and shared libraries. As someone noted in the comments, an informative read even by LWN.net's usually high standards.

2006-07-31

Decadence

I complete 10 years in the software industry today.

Ten years ago, as a lad fresh out of college and fascinated with computer programming, I felt tremendously excited that I had got a job where I could write computer programmes all the time.

That delusion was rather short-lived. I soon discovered that programming is actually a very small part of software engineering. Much of my time is spent writing specifications, communicating with my teammates and clients via email, conference calls and meetings, writing documentation, fixing bugs, giving demonstrations and presentations, etc. I spend more time within Microsoft Word than within Vim.

When I do get to write code, I have to write the simplest of programmes. The requirements almost never merit anything sophisticated. On the rare occasions where better data structures and algorithms can help, I still cannot use them since the code then becomes unmaintainable by the "average" software engineer. For an underperforming application, the standard solution seems to be to use a bigger machine instead of making the application more efficient. Developing "enterprise" software can be really dull and depressing for someone even mildly interested in programming.

FOSS.IN 2006

FOSS.IN/2006 will be held between November 24-26 at the J. N. Tata Auditorium in IISc Bangalore. This event used to be called "Linux Bangalore" and is justly touted as "India's Premier Annual Free and Open Source Software Event". It has been organised every year since 2001 by the Bangalore Linux Users' Group (BLUG). Atul Chitnis's diary entry has some more information.

I have personally attended only two of these events and I regret not having attended more of these. FOSS.IN/2005 was fairly good and mostly fun. I hope to be able to attend this year's event as well.

2006-07-25

ICFPC 2006

I participated in the ICFP programming contest for 2006 over this weekend. I was taking part in it purely for the fun of it (yes, really). It turned out to be a very interesting task. Check out the task description to see what I mean.

You have to first implement an interpreter for a simple but quirky virtual machine called the Universal Machine (UM). You then use this interpreter on the given data file ("codex.umz") to run a small programme that takes a password and uses this password to decrypt and uncompress a binary image. You then use the interpreter on this extracted binary image to discover a small UNIX-like multi-user system where you can log in as "guest". This system, called "UMIX", includes a set of common UNIX utilities like "ls", "rm", "cat", "more", etc., an interpreter for BASIC (called "Qvikbasic", that only recognises numbers written with Roman numerals) and a file-transfer utility called "umodem".

Using the guest account, you complete a simple password-cracking utiliy written in BASIC and use it to discover the passwords of a couple of other user accounts. When you log in as those users, you find more tasks that you can complete to discover the passwords of other user accounts, which yield even more tasks and so on till you get the "root" password. For example, one of the tasks was in the form of an Adventure-like game and another was using a "2-dimensional" programming language, complete with ASCII-art boxes for each function, to solve a given problem.

It was incredible and this is easily one of the best ICFPC tasks I have ever attempted.

You might also want to check out Mark Probst's account, Mauricio Fernandez's account, Gregory Brown's accounts (1, 2, 3, 4), etc.

The organisers also provided a handy benchmark for testing your UM implementation (called "SANDmark") and a reference UM implementation (in the form of a UM binary of course). If you want to quickly check it out, here is my UM implementation (written in C). You can use "(\b.bb)(\v.vv)06AAVKIru7p0OmCvaT" as the password to extract the UMIX binary image from "codex.umz" using this interpreter. (Paul Ingemi has even implemented a JIT-ing UM using LuaJIT!)

When I first implemented the UM, it ran quite slowly - it took a very long time for the UMIX login prompt to appear and over three hours just to compile "hack.bas" with Qvikbasic. I first tried simple tricks like converting indexed array accesses to incremental pointer accesses, caching values that were being used often, using a function-pointer-based dispatcher table to decode and execute instructions instead of a big switch statement, etc. but nothing helped. I found that the UM binaries allocate and deallocate a lot of "arrays" of various sizes and inspired by one of the posts to the ICFPC 2006 mailing list, I even implemented a system where arrays were only allocated in sizes of the smallest power of two larger than the requested size and recycled internally instead of being returned back to the operating system. However, even that did not help much.

That is when I decided to stop fooling around and ran the interpreter through qprof (I feel gprof and oprofile are not as immediately useful as qprof is - try it out and you would probably agree). I discovered that the real bottleneck was in the code that searched for a free slot to assign an index to a newly allocated array. When I eliminated that bottleneck by explicitly keeping track of freed slots, the performance of the interpreter improved drastically and it became usefully responsive. I eliminated the power-of-two array size foolery and it was still pretty responsive - malloc()/free() are really implemented pretty well in GNU libc and it is not usually worth it to second-guess it (except perhaps in extreme cases). (Also check out Doug Lea's notes on the design of a memory allocator.)

One of the wicked ideas from the mailing list did help however - using the pointer to an array's memory as its index instead of maintaining an "array of arrays", yielded a 20% boost in the performance of my UM implementation (as measured by SANDmark) but reduced its "portability" to only those machines where both integers and pointers are 32 bits.

The lesson learnt? We programmers are really quite bad at guessing the hotspots in our programmes. We should always use a profiler to find out where the real bottlenecks are in our programmes.

By the way, a few hapless souls discovered that the lack of unsigned integers in Java makes it unnecessarily difficult to implement something like this in Java. Why exactly couldn't the creators of the language provide unsigned variants of the integral types?

2006-07-21

Validating XML Documents

I was writing a couple of XML documents conforming to certain XML Schemata the other day. I was looking for a simple command-line tool that would take an XML document and an XML Schema and check if the document was well-formed and really conformed to the given XML Schema (I did not want to use web-based validation). I could have written a tool like this myself but I was feeling rather lazy and just wanted to quickly download a tool from somewhere to do this.

It turned out to be a surprisingly frustrating task and eventually took more time than what I would have taken to write it myself. Perhaps my Google queries were not good enough, perhaps people are just happy with their respective IDEs, perhaps everyone just writes their own little tool around the usual XML parsing libraries, perhaps people are not so anal about writing XML documents that strictly conform to the applicable XML Schema, etc. - I don't know why, but it took me a while to locate such a tool.

I first used Sun's Multi-Schema XML Validator (MSV) and it worked for me for a while but then tripped with a StackOverflowError on a particular XML Schema that I had to use so I had to abandon it. I next tried XMLStarlet but the error messages it spewed were a bit confusing and it did not fully support XML Schemata so I abandoned it as well. I am now using a little tool called "DOMCount" that is included with Apache Xerces and that ostensibly parses a document and prints out the number of DOM elements it has encountered but that also works fairly well as a document validator. The error messages shown by this tool, while better than those from XMLStarlet, can still confuse some times but I can live with it for the moment.

While creating these documents from the appropriate XML Schemata, I found xs3p [link currently seems broken] to be really useful. This is a stylesheet that takes an XML Schema and generates a pretty HTML document from it that you can use to understand the original XML Schema and easily navigate through its structure. I used Apache Xalan to generate the HTML documents.

New Delhi, US Visa and Kingfisher Airlines

I was in New Delhi at the beginning of this week to appear for an interview at the US embassy for a visa application for a business trip to the US in the near future.

This was my very first visit to New Delhi. I have finally fulfilled a long-held desire to see all the four metropolitan cities of India, viz. Delhi, Bombay (Mumbai), Madras (Chennai) and Calcutta (Kolkata). I was there for just a little over 24 hours, but I was still quite impressed with what I saw - wide, pothole-free roads with traffic zipping along at 50-60 kmph, lots of trees, everything spread out instead of congested together, etc. It did not feel like an Indian city at all. I am told that what I saw was just "New" Delhi and that Old Delhi is just like any other Indian city in terms of congestion and chaos. It's also rather myopic of me to judge a city by what I saw on my trips back and forth between my hotel in Connaught Place , the domestic and international airport terminals (a distance of about 20-25 kms) and the US Embassy.

However, others who have stayed in Delhi as well as Bangalore also insist that Delhi is a far cleaner city, has much less of traffic congestion and is a much larger city than Bangalore. I tend to agree based on what I have seen. I did not find Bombay, Madras and Calcutta much better than Bangalore - the awful amount of time you spend commuting in Bombay, the utter lifelessness of Madras for a youngster and the insanely congested traffic in Calcutta made me realise how much better off I was being in Bangalore than in any of these cities. With Delhi, I wasn't so sure.

While applying for a non-immigrant US visa, you have to fill out DS-156. One of the queries in this form that never fails to amuse me is:

Do you seek to enter the United States to engage in export control violations, subversive or terrorist activities, or any other unlawful purpose? Are you a member or representative of a terrorist organization as currently designated by the U.S. Secretary of State? Have you ever participated in persecutions directed by the Nazi government of Germany; or have you ever participated in genocide? [Yes/No]

Do they really expect anyone to answer "Yes" to that query?

My flights for this trip were with the new Kingfisher Airlines. I was quite impressed by them and would rank them higher than Jet Airways, the only other domestic airlines that I think has a reasonably good service. (My sister says that Paramount Airways is also quite good, but I am yet to travel with them.) Kingfisher has these little touches everywhere that score over Jet - the tickets are generally priced lower, you can select your seat over the Internet before checking in, when you arrive at the airport a valet takes your luggage, tags it, puts it through the security check and takes it to the check-in counter for you (no, I was not travelling Business Class but "Kingfisher Class", which is what they like to call Economy Class), there is an in-flight entertainment system to keep you occupied, the seats have slightly more leg room, etc. Oh yes, the air hostesses are really pretty too (with a bit too much of make-up I think, but quite pretty nonetheless). Wonderful.

2006-07-20

ICFP Contest 2006

Those interesting in programming might want to check out the ICFP Contest for 2006 which will be held during the coming weekend (21st to 24th July 2006). The problems are generally open-ended and fun to solve even if your entry does not make it to the top - check out the problems from the previous years' contests to see what I am talking about.

2006-07-19

All Your Blogs Are Belong To Us

We in India are no longer able to directly view blogs hosted on Blogspot, Typepad, Geocities, etc. This is because ISPs in India are blocking access to these popular sites acting on a government diktat to block some blogs "within the provisions of the Fundamental Right to free speech and expression granted in India's constitution" [sic]. Mridula was one of the first ones to notice and write about this blockade and the story has already made it to Slashdot and some of the mainstream media in India.

The government's diktat was to block a specific set of blogs ("to ensure a balanced flow of information") but since all the Blogspot URLs resolve to the same IP address, the blockade ends up blocking all blogs hosted on Blogspot. Ditto for Typepad, Geocities, etc. Since blogger.com is not blocked, I am able to post to my blog. I can also view my blog from my office since the Internet connection there is routed via a corporate proxy server located in the US. Using pkblogs.com, which was set up to allow people in Pakistan to view Blogspot blogs since they have a similar blockade in place, is another workaround, as is using a public proxy server or the Tor network using something like Torpark.

In 2003, a similar government diktat to block a specific Yahoo! Group had caused all Yahoo! Groups to become inaccessible from India. Thankfully that situation was resolved quickly and let's hope this issue is too.

A clueless bureaucracy eagerly assisted by a servile and clueless set of ISPs is not good news. Where is a cluebat when you need one?

2006-07-14

GCC Summit 2006

Just FYI, the proceedings of the GCC Summit for 2006 are now available online. They usually make for interesting reading for those even mildly involved with GCC in particular or with compilers in general.

2006-07-10

Presentation Skills

Most of us geeks seem to think that presentation skills are something for the marketroids or the suits to worry about. Even if we do have to present something, we only have fellow geeks in the audience who ought to be able to understand what we are talking about. However, geeks are humans too and humans need you to take care of certain things in your presentation for them to be able to fully appreciate and understand what you are talking about.

For example, in FOSS.in/2005 most of the talks were about cool stuff but in my opinion many a presentation left a lot to be desired. Among the talks that I attended, Jim Zemlin's talk about the Linux Standards Base was one of the precious few where the speaker seemed to understand and care about the basics of presentation.

Here are a few suggestions for speakers based on personal observations:
  • Keep the points in your slides short - avoid verbiage. Use the points to drive your talk - do not expect the audience to read everything off the slides. You can annotate your slides with explanatory notes if you want to upload the slides somewhere for people who were not able to make it to your talk.
  • Find out how much time you will have for your presentation, factor in the time usually taken up for questions from the audience and possible delays due to the previous talk and structure your presentation appropriately. You can have "checkpoint" slides in your presentation that you can use to gauge how well you are doing with respect to your plan.
  • Use clear fonts (I personally prefer scalable sans-serif fonts) and use a relatively large point size. People in the back should be able to make out what is written on your slides.
  • Spread your points evenly across a slide. Try not to list more than seven points per slide; use continuation slides to break up long lists of points.
  • Use foreground and background colours that have create good contrast. Remember that what looks good on your computer under ordinary lighting might look quite different when projected on a big screen in a darkened room.
  • Fancy transitions get pretty distracting pretty fast. Avoid them as much as possible except for things like progressively introducing the layers of a system, the phases of a handshake in a communication protocol, etc.
  • Do not keep your hands in your pockets all the time (a worse habit is to move them about in there). Gesticulate while talking - it's sometimes hard to know what gestures to use, so observe good speakers while they talk.
  • Make eye contact with the audience. Do not stare at a single person or throw fleeting glances at everyone. Hold eye contact with some random person for a little while, move on to another random person and so on.
  • Try an ice-breaker in the beginning to make your audience comfortable with you instead of just diving into your presentation. Humour is the best ice-breaker in my opinion but it takes talent to pull it off well. Some speakers use a quick show-of-hands kind of surveys. For one of his talks in FOSS.in/2005, Andrew Cowie put on his DJ hat and played various high-tempo tracks from his playlist while the organisers arranged various things for the talk.
  • It is usually not a good idea to declare "Feel free to interrupt me when you have a question". You will quickly discover that this ruins your flow and that there are several jerks out there who would ask a question just for the sake of it and to make their presence felt. You can pause your presentation at various "milestone" points instead and check if anyone in the audience has any questions to make sure that they understand the stuff being presented before moving on to other things.
  • The people in the front row might just shout a question across to you instead of using a microphone. For the benefit of everyone else, repeat the question before answering it (possibly rephrasing it) so that they know what is being discussed.
  • Ask someone to record your presentation and watch the video later. You will discover a lot of things you were saying or doing that you were not even aware of and some obvious areas for improvement. For example, the first time I saw a video of my own presentation I was dismayed by the fact that I had put on a pretentious accent for some reason, that I kept saying "Ok?" irritatingly often and that I kept my hands in my pockets almost all the time.
  • Do not stand between the audience and the projection of the presentation slides obscuring their view.
  • Depending on the nature of the presentation, it might be a good idea to distribute supporting material (brochures, printouts of the slides, etc.) before the presentation so that the people in the audience have a little background information or a take-home refresher. Printouts of slides can also be used by people (given enough space) to write notes corresponding to the slides.
  • If you can help it, do not talk about something that you are not excited about yourself. You will very likely give a better presentation about something that you genuinely believe in and care for than otherwise.
I can go on and on like this, but most of these points are obvious if you have any common sense or if you observe a good speaker. You can also search the web for a great deal of material on presentation skills. If your company offers a training on presentation skills, take it instead of sniggering and dismissing it as something for "losers".

Finally, here are a few suggestions for presentation attendees:
  • Please arrive on time. The cavalier attitude of most people towards punctuality causes unnecessary delays in starting a presentation and this has a cascading effect on the presentations following the presentation.
  • Please do not ask questions merely for the sake of asking a question. Before you ask a question, ask yourself if the question makes sense, if the question is relevant to the current talk, if the question would require an answer that would be better off discussed in a post-talk chat with the speaker, etc.
  • When you do ask a question, please use a microphone so that everyone else is able to make out what you are trying to ask. Please talk clearly and at a reasonable pace.
  • When using a microphone, do not ask a question seated on your seat - it becomes very difficult for people to locate you. Stand up while you ask the question.
  • Please do not come to a presentation merely to check emails, chat with friends, browse the web, etc. on your laptop using the wireless network made available by the organisers. It is being rude to the speaker and distracting to your neighbours.
  • Please switch off your mobile phones during the talk or at least switch it to vibrating mode. If you absolutely must take a call, please leave the room and take it outside so that you do not disturb others.
  • Try to be a bit discreet before walking out of a presentation - try not to walk out at all if you can help it. It is disheartening for a speaker to see people walk out of his presentation.
  • Try to hold off on that urge to talk to your neighbour. It disturbs everyone else.
Once again, you would think that all of this is common sense but it is surprising how many people are willing to forget all of these when they attend a talk.

2006-07-08

Books on C and C++

Tarandeep asked me what books on C and C++ I would recommend for someone who knows a bit of each of these programming languages. My problem is that I do not generally like reading books specific to a given programming language. In addition, I do not know C++ properly enough to be able to discern a genuinely good book on C++ from a mere pretender. He still insists that I write down a list of such books. I am therefore putting this list as a blog post in the hopes that people more knowledgeable about such things would help him out. We did search for such lists on the web but I was frankly not satisfied with the lists that we could readily find.

Here are the books on C that I would readily recommend:
  1. "The C Programming Language", Second Edition, by Brian Kernighan and Dennis Ritchie.
  2. "Expert C Programming - Deep C Secrets" by Peter van der Linden.
  3. "C Traps and Pitfalls" by Andrew Koenig.
(See also: List of books recommended in the comp.lang.c FAQ.)

Here are the books on C++ that I think should be useful:
  1. "The C++ Programming Language", Third Edition, by Bjarne Stroustrup.
  2. "Effective C++", Third Edition", by Scott Meyers.
  3. "Essential C++" by Stanley Lippman.
I did not particularly like Stroustrup's book, but it served as a useful reference when programming in C++.

By the way, many people do not like "The C Programming Language" but I am one of those who just love this book. It is a short book that is always to the point and has examples that teach you a lot about computer programming techniques and style. I agree that you should already know a bit about computer programming to fully appreciate this book. It was the book that I used to learn C. I love all of Brian Kernighan's books in general. He is one of the very few authors who have actually imbibed the lessons from "The Elements of Style".

In India, we have a few books on C and C++ written by some Indian authors that are terrible in my opinion but that unfortunately have been mandated as text books in several colleges here. The result is that many of the graduates who have not been exposed to other books form extremely warped ideas about these programming languages and about things like pointers. Sad.

2006-07-06

Pricing Your Time

We often hear clichés like "Time is Money" or "Lost Time is Lost Money". Most of us generally agree with these assertions but do not actually try to quantify the money associated with our time. We therefore rely on our intuition or mood to decide whether it is worth it to do something ourselves or pay someone else to do it on our behalf.

For example, does it make sense for us to fill out the relevant form and file our income tax returns ourselves or should we just pay the fees to an agent who will do it for us?

Suppose the agent charges 200 rupees for this service, you drive a motorcycle that gives you about 48 kilometres per litre of petrol in city traffic conditions, the price of petrol is 55 rupees per litre, the distance to the income tax office is about 15 kilometres and the parking attendant there charges 2 rupees. If you were to file the returns yourselves (filing income tax returns online is not yet fully available in India), you will directly incur a cost of about 36 rupees in fuel and parking charges. Assuming that it takes about 15 minutes for you to fill the form yourself and about 60 minutes for the trip to the income tax office and back, is it worth saving this time and pay the agent an extra 164 rupees for his service?

A couple of my friends and I used to amuse ourselves by trying to calculate our time's worth using our salary as a guide. Assume that your annual salary is about 4,00,000 rupees, your employer expects you to work about 8 hours every day from Monday to Friday and grants you a leave of 15 days in a year. With about 52 weeks in a year, that is about 246 working days or 1,968 working hours. This means that your employer is willing to pay you about 203 rupees for every working hour.

So in this particular case, at least from your employer's perspective, it is better for you to pay the agent the extra 164 rupees that he is asking for rather than waste about 254 rupees in lost (hopefully productive) time.

Technically we should also consider other factors like the price we are willing to pay to save ourselves the effort (in addition to the time) involved in the task, the amount of trust we place in the agent to do the job correctly and on time, our willingness to share the information about our income with a third party, the amount of masochistic desire we have to do our job ourselves, etc. This is therefore a very crude measure of the monetary value of your time.

A professor of Economics has come up with another formula to calculate the monetary value of your time and you might have your own method of calculating this value. Whatever method you use, these methods can be used to quickly tell if it could be worthwhile to do something ourselves or pay someone else to do it for us.

(I wrote this piece purely for its amusement value - it should not be taken too seriously and should merely be used as an indicator in the spirit of Burgernomics.)

2006-07-03

Superman Returns

I watched this movie over the weekend and was somewhat disappointed. The special effects were decent and more natural than in the original series of movies, as was to be expected, but the plot just had so many holes and the acting was so so-so that I was wondering how Bryan Singer and Kevin Spacey who gave us "The Usual Suspects" could have also given us this.

The New Yorker's Anthony Lane has written a far more eloquent critique of the movie than I can ever hope to write, but I would add that Brandon Routh is also about as good-looking as Christopher Reeve and is unfortunately about as wooden an actor. Of course, they are still nothing compared to Keanu Reeves when it comes to having a consistent lack of expressions throughout a movie. Perhaps having a chiseled good-looking face implies that your facial muscles are in a permanent rigor mortis.

There are some things that I would never understand about superhero stories. For one, why do they always have the same villain in story after story either as the main villain or as a willing aide to the main villain? Superman has Lex Luthor, Batman has the Joker, the X-Men have Magneto, He Man has Skeletor, etc. Do fans never get tired of seeing the same villains bugging their superheroes in episode after episode? Do they never wonder that if their superhero is all he is chalked out to be, why he is not able to get rid of this villain for good? Are they in fact aware of this irony and actively relish it?

Another thing that bugs me about superheroes is the need for almost all of them to have a mild-mannered alter ego. Why? And why can't other people recognise them in most of the cases? Clark Kent as the alter ego of Superman is particularly worrisome - does the addition of spectacles so change the facial appearance of a person that even someone close to them, like Lois Lane is to Superman, is unable to recognise them?

Yet another thing that really irritates me about superhero stories is the mess that all the hundreds and thousands of stories and story branches create. Again, Superman is the perfect example of this mess. Are there Supergirl, Superboy and Krypto, the Superdog, or not? Does Superman have a son or not? Has Superman died or not? Et cetera. What is the canonical Superman storyline?

Finally, why do most superheroes wear their underwear outside of their tights? What is it about superpowers that affects their sartorial sensibilities? In our college, a mild form of ragging involved the seniors making the freshers wear their underwear outside of their trousers, tying a bedsheet or a shawl around their neck as a cape and making them run down the corridors of hostels screaming "I am Superman!". Some of my friends would also remember our batchmate, who is now a banker in Bombay, running through the corridors of our hostel one night in an obviously inebriated state and clad only in an underwear and a bedsheet tied around his neck screaming "I am Superman!".

2006-06-30

Separating Debugging Information

Debugging information in an executable usually takes up a lot of space so developers usually "strip" an executable before shipping it. This however makes it difficult to diagnose problems in your programme reported by the users, especially when a problem is only reproducible in the reporting user's environment.

Microsoft's development tools support creating a separate "Program Database" (PDB) file for an executable containing debugging information for the executable. Its diagnostic tools support reading a PDB file for an executable , if one is available, to generate a more usable diagnostic report for a fault. You ship stripped executables to your users and when they report a fault, you ask them to install the corresponding PDB files to help you get a better diagnostic report. I think that this is a nice idea and I used to wonder if the GNU toolchain would ever support something like this.

Danny Smith pointed out to me that something similar is already supported by recent versions of GDB and binutils. You can use the --only-keep-debug option of objcopy for this purpose. For example:


gcc -g hello.c
objcopy --only-keep-debug a.out a.dbg
strip --strip-debug a.out


a.dbg now has the debugging symbols and a.out has been stripped of debugging symbols. When you want to debug a.out you can use:


gdb -s a.dbg -e a.out


Simple.

2006-06-29

Tales of Human Resources

In an organisation that I once worked for, the Human Resources department was particularly prone to engaging in activities and issuing diktats that were rather Dilbert-esque. Here I recount a couple of egregious examples of this behaviour that unnecessarily damaged the careers of several employees for absolutely no fault of their own.

At that time, the employees in that organisation were awarded grades every year reflecting their perceived performance based on appraisals by their peers, their seniors and anyone working under them. The grades ranged from A (exceptional) to D (unsatisfactory) and affected how much of a hike in salary (if any) you get when the next round of salary hikes takes place. They also affected the chances of your promotion.

Someone in the HR department read somewhere that the distribution of these grades in a large organisation usually follows the bell curve of a normal distribution with a few employees being graded exceptionally good or marked unsatisfactory and most employees being graded good or merely satisfactory. This person then made the leap of logic in deciding that the distribution of these grades must necessarily look like a bell curve and that too for each team in the organisation!

Needless to say, this had a very bad effect on some teams and our team was affected especially badly. Our team was assembled by hand-picking the best people from a lot of teams across the organisation to work on a particular project that the company perceived to have a lot of potential at the time. It was natural for almost everyone in the team to perform well and the managers mostly awarded Bs and As. The HR department, of course, would have none of this. The distribution must be "normal" across the team and all the pleas of the managers fell on deaf ears. The result was that some of our team members were awarded a D even though they had done good work throughout the year! This had a predictable effect on employee morale. A lot of people from the team left the company very soon.

The same organisation also had an unwritten rule of letting go of the bottom 5% of the employees of the organisation every year judged by their performance. The merits of this kind of a rule is, of course, debatable but once again a diktat from HR made it even more damaging. They decreed that every team should let go of the bottom 5% (rounded up to the nearest whole number), irrespective of whether there was actually anything unsatisfactory about the affected employees. Once again managers pleaded in vain with HR and were helpless as useful team members of a project were unnecessarily laid off. The crazy thing is that hiring continued to go in full swing during this period. Some managers thought they could take advantage of this and hire back the laid-off workers but HR nipped their plans by reminding them of the policy that an employee could not join the company after leaving it for a period of at least six months.

These incidents were not only devastating for the morale of the employees directly affected, but they were also depressing for the rest of us. Ironically, one of the purported aims of the HR department was to devise ways of boosting employee morale. Their actions however had the exact opposite effect.