Last night I dreamt I was a StringBuffer()...
This happens rather often with me. Having programmatic dreams I mean. Not being a StringBuffer, or I should be at the funny farm. I've got most of my brilliant solutions(or so I think) in my dreams.
I remember one of our computer science projects at school (in fact, I have a poem composed about my projects, but that is another story)- way back in '92. I was trying to program an animation of a volcano erupting- in GWBasic (how I loved that language). I don't remember the exact problem I had, but it was something to do with the lava pouring down the sides of the volcano. And I remember working on it all night and not getting anywhere. While I slept, the solution struck me- I woke up, noted it down and went back to sleep. Next morning, I found a couple of lines of code written on a scrap of paper on my desk- I tried it out, and it was the most beautiful volcanic eruption I'd ever witnessed!
If it's not a solution, I end up with nightmares of the problem. Yesterday, we were confronted with the problem of optimizing a program that dealt mainly with strings. Basically, it reads XML-like text from an input file, discards about 70% of the file which we are not interested in, and saves the interesting stuff to another file as a well formed XML document. Well, as usual, it worked fine on our test files of about 50MB. Then, we heard that it was taking 3 hours plus with input files from the production server- and that input file was only 30MB. Needless to say, we were worried. Very worried.
Apparently, each line in this file was 120KB or more. And that's where the problem lay.Took a look at the file, had countless discussions which were spent more on abusing the file itself, and then saw that we were reading character by character, building a substring which contained the full XML tag, and then discarding it if we didn't need it. What I realized is that the damage was done by reading the junk- 70% of the file. So why were we even reading the junk? I re-worked the logic to jump into the file, and pick out the first occurence of non-junk. And then throw out everything above it. So automatically, the string we have to handle is smaller. And then find the end of the tag that interests us, and cut that out and work with it. Repeat the process. So we get successively smaller and smaller strings to work with. Considering the junk tags were very large, it worked.
But I distinctly remember dreaming only of strings last night. Replacing strings, deleting strings, indexOf(), substring(). And that's bad. Considering I slept right till noon. Woke up and had my breakfast. Went back to sleep at 1pm and only awoke at 5pm. That's a long time to dream about Strings. Oh well, better strings than pointers :)
I wish I could program my computer to play this song everytime the doorbell rings on a Saturday or Sunday morning:
Who can it be knocking at my door?
Go 'way, don't come 'round here no more.
Can't you see that it's late at night?
I'm very tired, and I'm not feeling right.
All I wish is to be alone
Stay away, don't you invade my home...
Who can it be now? -Men At Work
Sunday, November 21, 2004
Dream On
Subscribe to:
Post Comments (Atom)
3 comments:
I swear on the pot - It wasn't me!
Sweet dreams!
Sorry, String dreams!
Luanne, I never knew you wrote so well. My my...I'm absolutely awestruck. You humble me woman!
2BLuE
http://groups.yahoo.com/group/VAYU/
It is a common experience that a problem difficult at night is resolved in the morning after a committee of sleep has worked on it.
- John Steinbeck
Post a Comment