Saturday, March 03, 2007

Compiler Design....

Before I dive into the meat of the topic, I would like to mention that I am a HUGE fan of Per Brinch Hansen... so whatever viewpoints I express in this post, will totally be partial to him.Per Brinch Hansen is teaching me Compiler Design this year and I need to implement 6 phases of a compiler, for a minimalistic language(PL), incrementally for the course completion. I am already done with the scanner and parser.Programming should be a thoughtless process. It should be as obvious as Maths.

Most of you guys(that is, if you are in Computer Science) would have taken design courses(OO etc ). How many times did you have trouble implementing a properly designed code? If your design is good, you should have none, but the idiosyncrasies of the programming language sometime do corner you at some nasty implementation issue. Everyone has seen a nasty memory leak or a typo ruining the whole logic of your implementation. According to Prof Hansen:
Programming should be a thoughtless process. It should be as obvious as Maths. If you are asked the value of 5+2, you would say 7. Have you ever stopped and tried to derive that. Programming should be like that.
Yesterday I was writing the parser, which mainly involved sifting through the PL code and producing a JAVA implementation for the PL's BNF. PL's grammar had some 50 rules which needed to be implemented in the form of around 50 functions. Following the design rules and restrictions imposed by him, I was able to code the parser in just four straight hours!! The code compiled with no syntax errors!! I spent around a day testing it rigorously..and nothing failed!! In fact at one point of time, programming seemed more like documentation. I even wrote vi macros to construct the function skeleton from the grammar rule in the comment (I hate typing:P ). Cant wait to finish rest of phases...

PS: BTW the EFS project ,I was talking about in the earlier post, is implemented and all the issues are resolved. Too bad its proprietary :(

PPS: A colleague forwarded me this link. Turn out that Per Brinch Hansen was the one who came up with the idea of an OS kernel!!

Saturday, February 10, 2007

Am I an engineer?

The most appropriate heading would be "Are software engineers really engineers??". I'll get to that in a minute. According to Wikipedia:
Engineers apply established principles drawn from mathematics and science in order to develop economical solutions to technical problems. The work of engineers is the link between perceived social needs and commercial applications. Engineers consider many factors when developing a new product.
There in another word, CRAFT... according to the Wikipedia again:
A craft is a skill, especially involving practical arts. It may refer to a trade or particular art.Crafts practiced by independent artists working alone or in small groups are often referred to as studio craft.
The only thing that distinguishes craft from engineering is objective logic and intuition. There is no place in engineering for the "feel good" factor. It just a simple cold manifestation of science in a practical form, which in turn is just simplified mathematics represented in language understandable by humans.

So why is software development a feat of engineering? and not a craft?
Now there is nothing wrong with it being a craft. New craftsmen are trained by a master craftsman (something like internship/co-op).. they mimic everything the master does to achieve the end result. This works for general arts and used to work for medical science too few decades ago. So if you were to learn software development as a craft from the "experienced" developers, you would mimic everything they do... even if it involved throwing a dead frog after declaring each variable in a file, and it will not lead to a catastrophe until you are copying everything that the master developer does.

Advancement in technology has given so much slack to us "Computer scientists/engineers" that we do not evaluate the consequences of our action. We do not look at a problem as an engineer in other field would. Take an electronic or mechanical engineer for an instance. How many time have you known that they designed a system that failed or had a bug? Bugs are a commonplace in software engineering. Infact it is widely acknowledged that a shipped software will have bugs.. then there will be an upgrade or a patch released to fix that bug.. and then another..and another ...and so on. This is mostly due to the fact that most software rarely effect human life... but when a "crafty" software developer does write a such a software, we are in for some serious trouble.

Not all the software development fraternity works this way. There are certain organization that are required to develop 99.9% bug free software or risk loosing a million dollars or a million lives. NASA is one such company, a bug in code would mean loss of over a billion dollars.. and guess what! they don't do version upgrades on space vehicles. It does what it is supposed to do. No one is perfect though, the MARS land rover running Linux had a small race condition and that had jeopardized the whole multi billion dollar project... and imagine the mental state of the computer programmers who had the whole world looking over their shoulders, ready to point fingers should anything go wrong. Fortunately they recovered with minor losses. Boeing is another one, from auto pilot to auto land, everything depends on the software... a small bug would not only cause the death of many lives aboard the plane, but would also lead to the destruction of the multi million dollar equipment. Forget the biggies, the real time and embedded software developers are also better engineers because their software control the expensive machineries. Then we have the financial developers like Bloomberg... the whole money making fraternity depends on them, from Goldman Sachs to JP Morgan. A simple miscalculation can lead to a loss of billions of dollars.

I am an engineer/scientist by education, but its my profession that will decide what I really am;an engineer, a scientist, a blue collared programmer or a craftsman. After all as Batman said..
It's not who I am underneath, but what I do that defines me.

Thursday, February 01, 2007

EFS on Minix: Design Issues

I am implementing an encrypted file system(EFS) on Minix3.1.2a. Although the implementation is not all that difficult (infact it is really easy), the design is certainly not trivial.

Lets assume a simplistic case of one user per system and lets assume that his key(or password ) will never change. In such case, the only thing that needs to be done is
  • Reading a block from the disk and decrypting it before placing it in the cache/queue/routine.
  • Encrypting the data before writing it back to the disk.
In Minix3.1.2a, rw_block() is the only function that needs to be modified (I mean the meat of the implementation goes here). This is not a difficult task to accomplish, but the key management and the group management issues are really tricky. Here are some of the issues:

KEY MANAGEMENT:
  • A user X has key Kx. His 25000 (say) files are encrypted using Kx. Now a computer savvy guy that X is, decides to change his password. What would the system do now? Decrypt all his files and re-encrypt them using his new key?
  • Here's a solution: Suppose X has two keys K1 and K2. K2 is used to encrypt his files and K1 is used to encrypt K2, so when X logs in, he is able to unlock K2 and read his file. His encrypted K2 is, of course, stored on the disk. Now thats a file too... how will that be encrypted? Who will encrypt it? Remember that the whole purpose of an EFS is to protect the data on a hard disk on an event of physical compromise of a system... and you cant make that file, not follow a rule.
GROUP MANAGEMENT:
Now X encrypts his file using Kx. Then he joins a software company and is asked to collaborate with other employees. The system admin puts him in a group, the member of his group are his colleagues who share the files. How will other's read his files which are encrypted with his password??

The future looks bleak now... there certainly have been many attempts to solve this seemingly easy problem with no avail. Microsoft provides an ad-hoc solution by allowing individual files to be encrypted. Group access cannot be added although individual users can still be added. This leads to an elongated file header and I don't find this design all that attractive or well thought out. One solution, that looks a bit futuristic, used a smart card but that is not an option in my case .

Hmmmm..... its an interesting problem. Think about it. I will...

PS: There will be few solutions on the wiki pages that I have linked to. They are too complicated to be correct and lack of libraries to do those stuff on Minix will make my life hell if I choose to mimic them... nevertheless it should not deter me from implementing such a system on Minix. And after all as my Professor Per Brinch Hansen says :"Simplicity is intelligence, multitude is stupidity"

Friday, January 26, 2007

Trip to India...

I have already written about my travel ordeal, so would be writing about the places I visited: Kanpur, Bangalore, Goa and Chennai.

KANPUR: For those of you who dont know me well enough, I spent the first 18 years of my life here (that does make me sound old). I have no particular affinity to place (yes i am heartless) and went only because my parents live there and to visit my old school(spent 14 years studying here).

This place never fails to shatter my notions about life. I arrived at Kanpur on 19th dec'06 only to find 12hour powercuts and a 2-3kbps connection called Reliance High-Speed Data Connection... which supposedly is some sort of improvement over dial-ups. One would think that I would be frustrated with no electricity and no internet... but I wasn't. Yes I didn't read Digg every 10 minutes, did not blog every week, did not check my mail every 5 seconds, did not watch videos online, or did not surf the 100+ channels we get on television... but it was really relaxing not to do all these things. After 1.5 years of running on the information highway, it was great to settle down for a month. This gave me ample of time to bond with people, talk at leisure with my family, make small talk with neighbors, give advice to wannabe engineers... without thinking about anything else in the back of my head. It was as if I had my garbage collection done.
To top it all, there was a reunion at my alma mater. It felt great to return to the place after 6 years and see some long forgotten faces.

I didn't do any touristy thing here. Living without a broadband internet in an old industrial city(350+ years old) was touristy enough for me.

GOA: What can I say... I spent the New Year here. It was crowded with people from all over the world. That, coupled with a warning from Al Quaeda added a few policemen to the already crowded place. The entries to the local clubs and pubs shot up by 600%, rendering them inaffordable to poor students like me. Rest assured, it was heaven... albeit a crowded one.

BANGALORE & CHENNAI: I did my engineering in Chickballapur, 50km from bangalore, so most of my friends are in Bangalore. Most of my friends from Kanpur have also relocated to this area, making it impossible for me to meet everyone of them. I ended up sending bulk mails on community websites, asking for phone numbers of people who want me to contact them. I called few of them and scheduled time slots to meet the rest of them. Unfortunately, I did not leave buffer time between the appointments so ended up saying "Hi" and "Bye" at the same time :( ... people need to be more punctual. I was in Bangalore for two days, in which I met my relatives, went to my undergraduate college to collect some papers, and met few of my friends. Trip to Chennai was relatively less stressful.. I just relaxed at my Aunt's place and spent my days there in front of her "wall mounted, 72 inch plasma display, home theater system".

All in all, my trip to India was what I wanted it to be... refreshing.

Wednesday, January 17, 2007

Sridhar's log... stardate 200701.01: Travel Ordeal

I am back. Its been ages since I blogged, sorted my mail, read blogs, chatted online, uploaded pictures... i.e. did anything on computer. Since the whole trip cannot be covered in totality in a single post, I'll posting multiple entries about it. This one is about my traveling experience... It is not for people with weaker hearts :P.


Although I booked my tickets a month early, I didn't look at the itinerary. I delegate work whenever possible, so assumed automatically that my agent (U.V. Travels) will plan the best itinerary for me. What happened next was a disaster:
  • To India: I flew by Turkish Airlines. Without doubt, it is the most incompetent/inconvenient airlines I ever flew in and would ever fly. The in-flight entertainment systems belonged to the stone age. They had an old projector, which had three separate lights(RGB) that tried to create a pseudo color projection... it didn't go very far. The volume/channel controls were outdated and used some sort of mechanical dials.. none of them worked. Fast food was served on the plane... which was again a disaster because I am a vegetarian and my agent didn't seem to consider my food preferences while booking the tickets, but it was manageable. There was a layover in Turkey...for 14 hours!!! The hotel at the Airport has only 20 rooms, 5 reserved for the airlines... which are given to families and not single bachelors. I spent 14 hours sitting on a wooden chair/couch in a Starbucks cafe... It was more painful than it sounds. There was free wifi at the airport but no ports to plug in the power cord.


    The flight was till New Delhi, after which I had to take a connecting flight to Lucknow and then get a ride to Kanpur. At New Delhi airport, I realized that I had booked the flight for 19th jan rather than 19th December!! I took a train to Kanpur (paid another unscrupulous agent three times the fare)

  • To Goa: I was supposed to fly to Bangalore, and go for a road trip to Goa with 8 other friends. The flight to Goa got canceled, had to rebook it at twice the price... small price to pay to meet priceless friends I thought. Reached Bangalore at around 7pm and had to leave for Goa at 9:00 pm. At 9:00pm I was informed that 6 of them had dropped due to some reason. Instead of 9, three of us went for the trip to Goa in a Tata Indica. We took NH 4a.. which despite being a National Highway was the worst road (no there was no road) I have ever seen... The engine cover was damaged, the axle bent and the wheel alignment destroyed. Fortunately there was a garage near the end of the road... The road trip took us over 15 hours...

  • Back to US: Turkish Airways again... but a 19hr layover this time. Got accommodation in a lounge which made it more bearable. The flight from JFK to Syracuse got delayed by half an hour, then got delayed by another 3 hrs... and then finally got canceled. Took a bus to Syracuse and reached 6 hrs later than the estimated time.

Distance travelled:
By Air: 24000 km
By Road: 2000 km
By Rail: 2400 km

I can safely say that I traveled ALOT!!