Serial Writers on the Loose

Serialization is the process of writing data out in a storage medium in a pre-defined format so that it can be read back programmatically. Even though there can be many forms of Serialization (even usage of databases is Serialization in some sense), in most cases, serialization is used to persist the program state onto a file and read it back so that computation can proceed from an intermediate state.

I remember at one point of time, I used to fret and worry about having to decide a format to write my data in, and then write procedures for writing them out into a file and then reading them back. And then look for minute bugs which crop up in this process. Developer productivity goes for a six while the manager manages a sinister laugh in the sidelines as the employee sweats it out with printf and scanf.

No more! Thankfully there is something called object serialization that comes to our rescue. With the dawn of languages such as Java and the .NET platform, serialization was made very simple, in fact so simple that little cherubs (in their garden playing harps or rather System.IO.Harp) could just add a single attribute to the class name and all the perspiration is taken care of by the framework.

In the .NET framework, serialization can be very simply implemented by adding the [Serializable] attribute to the class. Any fields that one doesn’t want to be serialized can be marked with a [NonSerialized] attribute. Thereafter, you just use a BinaryFormatter to format data into a suitable binary format, open a FileStream to write it out to a file, and bingo, you’re done!

However, I was not convinced it could be so easy. The objects typically form a graph structure and might be cyclical. Would the automatic implementation of .NET Serialization be able to handle this cyclical structure, or would I need to fish DFS and BFS from my old dusty textbooks, parse them in an acyclic manner and write them in a suitable order. All my worries were misplaced! It just works… it’s magical. You can be a dork and use the object serialization in .NET!

There is a small catch though. Static fields of a class are not serialized automatically (among some other gotchas). And you need to implement the ISerializable interface and provide custom implementations of the GetObjectData method and a constructor of the class which takes SerializationInfo as a parameter (See some examples here) in order to deal with these special cases. In my simple case, I had an identifier for every object which I allocated based on a idCount variable which was a static integer. Hence, in the custom constructor, I set the value of the idCount to the highest id value I had seen so far during deserialization so that I don’t generate old id values gain.

id = info.GetInt32(“id”);
if (( + 1) > idCount)
idCount = ( + 1);

But still, object serialization is a great boon for most of us developers who don’t wish to tear their hair out trying to write code that is not even important for their work!

Ok. So, I discovered that in case you override the Serialization using the ISerializable interface, you need to override it for all the derived classes. A lot of hard work I am not willing to do. Another trick could be that in case of the base class, instead of implementing the ISerializable interface, implement the IDeserializationCallback, which essentially lets you override the OnDeserialization method which is called after the deserialization is done, and you can write custom logic there to populate the static or the Non-Serialized fields.

Vint Cerf

Vinton Cerf, best known for having written the Internet Protocol, which is the substrate of the internet, gave a talk today in Bangalore at Ambedkar Bhavan. He is an ACM Turing award winner, the highest civilian honour in Computer Science and currently serves as the VP and Chief Internet Evangelist at Google. One thing I found surprising was that even though Google organized the talk, I could not find any references to the talk anywhere on the Internet (searched on Google of course), except for this blog. I had expected Google to put up a searchable page online at least regarding its much advertised “Google Speaker Series”. I saw the advert in the papers and later wanted to find more details, but alas! it seems they dont have a good PR person.

Anyway, coming back to the talk. I felt that the talk was a little too high level. That is mostly what happens in such talks where the speaker has to cover a lot of ground in a small space of time (Spacetime?). I felt Raghu Ramakrishnan handled it better — he elaborated on a specific application (DB Life). A few takeaways from the talk were:

  1. During the design of the IP Protocol he decided to keep the design independant of both the applicaiton (it just works on bytes) as well as the infrastructure (IP works on all concievable connection system from telephone lines, ethernet, ATM, VPN) and it has stood IP in good stead since. This independence ensured that lots of new applications (some of which even surprised Vint, such as a internet-enabled surf board) as well as new tele-infrastructure.
  2. Mobile users in India are about 200m as compared to 40m or so internet users. What is the medium of choice for connectivity in the future?
  3. Of about 1b internet users, around 400m are in Asia with China and Japan accounting for around 150m each. North America is only third after Europe. And we thought internet is in English.
  4. As more and more devices get online, there will be many more applications.
  5. Hardware has improved substantially thanks to Moore’s law, but software has not kept pace. Higher level languages such as Python have not helped much. Perhaps they should all shift to Lisp :). He also seemed to believe Ajax is a high level language. I am not sure how — perhaps my understanding is flawed, but I used to think it is only a mechanism for ensuring asynchronous call backs on web pages with very few language level features (which would definitely be desirable).
  6. He seemed to make a strong point for Formal Methods in Software Analysis to find out bugs in Software and be able to give guarantees.
  7. He seemed to believe that our current infrastructure needs to incorporate security as a first class design parameter. Concepts such as VPN sit atop traditional networks like a veil, but with increasing mobility, the need for security being fundamentally encoded in our design is a requirement.
  8. Similarly, prediction of internet usage (similar to Erlang in Telecom) and QoS are perhaps desirable but have technical difficulties and these make them important problems in Computer Science.
  9. The QnA was mostly irrelevant — What will Google do in future? What does Google use apart from PageRank? How can internet be made more accessible in India? With (mostly) even more irrelevant answers.

It would have been nice to hear more about his experiences in the actual design of IP.

Indhan by Gulzar

A poem by Gulzar sahab. I have always loved Gulzar sahab’s poetry — always found his songs a cut above the regular fare at Bollywood. They are musical, harmonious, rhythmic both in words as well as meaning:


छोटे थे, माँ उपले थापा करती थी
हम उपलों पर शक्लें गूँधा करते थे
आँख लगाकर – कान बनाकर
नाक सजाकर -
पगड़ी वाला, टोपी वाला
मेरा उपला -
तेरा उपला -
अपने-अपने जाने-पहचाने नामों से
उपले थापा करते थे

हँसता-खेलता सूरज रोज़ सवेरे आकर
गोबर के उपलों पे खेला करता था
रात को आँगन में जब चूल्हा जलता था
हम सारे चूल्हा घेर के बैठे रहते थे
किस उपले की बारी आयी
किसका उपला राख हुआ
वो पंडित था -
इक मुन्ना था -
इक दशरथ था -
बरसों बाद – मैं
श्मशान में बैठा सोच रहा हूँ
आज की रात इस वक्त के जलते चूल्हे में
इक दोस्त का उपला और गया!

- गुलज़ार

Indhan literally means fuel. The poem starts off describing uppla, or cow-dung cakes used to feed the fire in the villages (and cities) of India. The end however is philosophical because in the larger picture what are we humans but the fuel to the fire of life. The multitudes whom we know as brother and sister, father and mother, spouse and friend are drops of oil in this yagna of existence. All we do is fuel the fire in the crematoriums. A translation is given below:

When we were young
Mother splayed some dung
On the wall
Called it upla

And we
Put faces on,
Eyes, ears
A nose
The upla with a turban
A cap
My upla
Your upla
We named them as we pleased
Chosen after our hearts

The playful sun
Spread its warmth each day
On our uple
And when the chulha was lit that night
We gathered around it and waited

Whose turn was it going to be tonight?
Who would burn to ashes?
There goes Pandit
That was Munna
This was Dhashrath

Years later
I’m at the crematorium
Tonight, I watch
As another friend is lost to the burning chulha
One more upla reduced to ashes


The poem has been shamelessly lifted from Kaavyalaya and the translation is from The Little Magazine. I liked both the resources immensely.

Have also been spending time reading Jhaansi ki Raani (Subhadra Kumari Chauhan), Maa Keh Ek Kahani and Arya (Maithili Sharan Gupt).

The Hanging Circuits of IIT Kharagpur

This guy’s a genius!

Why do people fall in love?

[Perhaps the title should have read Why don't people rise in love?]
Because love is like a well — It is easy to fall into it, but tough as hell to climb out.

IITs: What does the future behold

The Times of India today carried a Special Report on how the IITs are facing a faculty crunch. Since the faculty salaries are linked to the pay commission, the IITs have to pay their faculty on par with Central Government employees everywhere else. What that means is that they can’t pay professors even if they have enough money.

The hostel facilities are deteriorating by the year (I can vouch for that). The additional reservations and the 54% increase in seats is not going to help that cause since the increase in seats has to happen within a year or so and it is humanly impossible to build so much of additional infrastructure. In fact, I remember a professor once asking a very innocent question:

Will our drainage and sewerage system be able to handle all these new students?

Most IITs have stepped up efforts to receive funds from alumni. There have been generous grants from individuals such as Kanwal Rekhi ($5m to IIT B), Vinod Gupta ($5m to IIT KGP), Nandan Nilekani (IIT B), Vinod Khosla, Arun Sarin, Arjun Malhotra and many others. However, the alumni foundations have not been able to put their acts together and create the kind of endowments that US Universities enjoy ($25B for Harvard). I am not sure if IITs can create such endowments primarily because they don’t have the 300 year histories that these US schools have. Creating an endowment which can sustain the annual budget of an IIT (which I am sure will be to the tune of hundreds of crores) with its interest amount, will require at least a billion dollars in endowment. It’s not an easy task.

There is another hope. As the Chinese proverb goes, Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. Lately, IITs have started earning revenue by licensing technology and performing sponsored research (see end of this article). IIT Kharagpur’s Sponsored Research and Industrial Consultancy division has been a pioneer in this area having already handled tons of sponsored projects. I feel this might be the right way forward for IITs since this will provide a constant revenue stream. By sharing project benefits with professors, the IITs will be able to tackle the issue with the professor’s salaries as well. They could try to kill two birds with one stone!

Another area the IITs can develop is entrepreneurship. Nobody doubts that IIT produces some of the smartest undergraduates in the country. By providing sufficient mentoring and support, the IITs could channelize their energies toward commercial successes. Material benefits for all stake holders, students, professors and the IITs is only a natural consequence. Entrepreneurship Cells have started mushrooming in many IITs. One only hopes to see major successes shortly.

India benefiting from its neighbours?

An article in the Economist believes that regional unrest has been helpful for the country:

In some ways India benefits from the fact that so many countries around it are a mess. It attracts investment and trade that might have gone to the neighbours. Its garment makers, for example, have won business diverted from Bangladesh because of political turmoil there.

India’s achievements—a stable, almost uninterrupted democracy, and a fast-growing economy that dominates the region—look all the more impressive set beside the failings of its region.

The article goes on to say, however, that even though the country may have benefited to some extent, if India wants to maintain its rapid pace of growth, it should strive for regional peace and harmony, perhaps even lend a helping hand to its ailing neighbours since regional strife could cost the country much more in the long term:

In its present buoyant mood, India may think that it can cope readily enough with living in a low-rent, violent district. Fine―until something big goes wrong. India’s rising international prestige and economic allure could both be put in jeopardy if the country is sucked into some headline-grabbing regional conflict. The best way to reduce that risk will be to find ways of helping the neighbours with a bit of gentrification here and there whenever the opportunity arises, however grudging they may be in their response.


Get every new post delivered to your Inbox.

Join 1,843 other followers

%d bloggers like this: