Wednesday, October 19, 2005

Del.icio.us code

I came across this snippets site and I think its a damn good idea. You can store some interesting code snippets which you might have come across on the internet and it is available always. Very similar to del.icio.us but this is for code snippets.

I have come across a lot of times when I say or hear other people say something like: "Oh! I had done this before somehow...but i seem to have forgotten it!" or "I had seen the soution to that when i was searching for something else but I dont know where on the web I found that code".

Hmm...Why dont I come up with ideas like this which are very simple but are so useful?

Wednesday, October 12, 2005

The Cat ate my source code

This post is related to my previous post

This one is from 'The Pragmatic Programmer - From Journeyman to Master' :

Time for a little quantum mechanics with Schrödinger's cat.
Suppose you have a cat in a closed box, along with a radioactive particle. The particle has exactly a 50% chance of fissioning into two. If it does, the cat will be killed. If it doesn't, the cat will be okay. So, is the cat dead or alive? According to Schrödinger, the correct answer is both. Every time a sub-nuclear reaction takes place that has two possible outcomes, the universe is cloned. In one, the event occurred, in the other it didn't. The cat's alive in one universe, dead in another.
Only when you open the box do you know which universe you are in.

No wonder coding for the future is difficult.

But think of code evolution along the same lines as a box full of Schrödinger's cats: every decision results in a different version of the future. How many possible futures can your code support? Which ones are more likely? How hard will it be to support them when the time comes?

Dare you open the box?

Sunday, October 09, 2005

'Cat'chy Reality

I recently finished reading this book. It is an awesome read if you are interested in what reality is and where modern physics is pointing to. It looks like the distinction between scientists and spiritualists is blurring away. The way you look at the world starts slowly changing. Especially the many worlds interpretation is a very interesting one. After reading it I have started thinking in that way unconciously.
Let me try to put it in as few words as possible:

The Cat paradox
Imagine a box that contains a radioactive source, a detector that records the presence of radioactive particles, a glass bottle containing a poison such as cyanide, and a live Cat. The detector is switched on for just long enough so that there is 50-50 chance that one of the atoms in the radioactive material will decay. If the detector does record such an event, then the glass bottle is crushed and the cat dies; if not, the cat lives.
We have no way of knowing the outcome of this experiment until we open the box to look inside.
The whole experiment is governed by the rule that the superposition of both the outcomes of this is real until we look at the experiment, and that only at that instant of observation does the decision happen and one of the outcomes is seen.

The Many worlds Interpretation
This theory says that both the outcomes of the experiment are equally real. The surprise is that according to this theory there is not one real cat but two. There is a live cat, and there is a dead cat; but they are located in different worlds.
Faced with the decision, the whole world - the universe - split into two versions of itself, identical in all respects except that in one version the atom decayed and the cat died, while in the other the atom did not decay and the cat lived.

It sounds like science fiction but it goes far deeper that any science fiction. It is a truth stranger than any fiction.


Sunday, August 28, 2005

Capitalized!

I had not blogged for quite sometime now. The reason is that I am now in Delhi (Gurgaon) for a week now and I was busy setting up stuff. We are put up in a hotel in gurgaon. We are here doing 'consulting' (whatever that means) for a client of ours.

This is my team standing in front of our office excepting one who is taking the snap. Will put up nicer snaps when I get the time to shoot. This project seems to be challenging in terms of client facing, communicating, convincing, etc. Lets see how it goes. But one sad thing is that I had to cancel my trip to Leh because of this project. But as long as there is something new to learn,I am for it.

Sunday, August 07, 2005

Face the Music

Most of the people around me listen to music while working. I see them with ear-phones/ headphones, nodding their heads, enjoying their music, and their work. Even I have tried that lots of times, and miserably failed. I have found that if I am in the midst of something serious and interesting, which requires a lot of my concentration, I just can't listen to music. If I am listening to it, I lose the hang of whatever I am doing and my mind gets involved in the music.
The music just takes over the whole of my mind and I sort of lose my context completely.
I don't know. It might be that I am poor at concentration, or it may be that I am more interested in music, or it might also depend on what kind of music I listen to.
But, whatever it is, this is how I am...

Tuesday, August 02, 2005

What is meant by Data?

I saw a very interesting piece of code in the SICP. It took quite sometime for me to understand it completely. In fact, the meaning flashed to me today during my morning jog!

In a programmer's perspective, what exactly is data?
This is a very subtle concept. Very difficult to explain.
Data is something that is constructed and behaves in a particular way. i.e, What data is, is determined by how it behaves.
How do you say this programmatically? - Data is that which is defined by constructors and procedures, together with specified conditions that these procedures must fulfill in order to be a valid representation.

Example: consider the notion of a 'pair' in lisp. A 'pair' is a way of glueing two pieces of data. This is how I will probably explain it:

(define z (cons x y))
(car z) => x
(cdr z) => y

We never actually said what a pair was, only that there are procedures cons, car, and cdr for operating on pairs. But the only thing we need to know about these three operations is that if we glue two objects together using cons we can retrieve the objects using car and cdr.
The interesting thing is that any triple of procedures that satisfies the above condition can be used as the basis for implementing pairs. This is one such triple:

(define (cons x y)
(lambda (m) (m x y)))

(define (car z)
(z (lambda (p q) p)))


(define (cdr z)
(z (lambda (p q) q)))


This point is illustrated strikingly by the fact that we could implement cons, car, and cdr without using any data structures at all but only using procedures. This blurs the distinction between 'procedure' and 'data'. Procedure <---> data. Data <---> procedure. Hmm...I need to think.

Friday, July 29, 2005

... and somebody had time for this.....

All my earlier posts are quite big.. I want to keep this small:
Obviously you would have come across a lot of useless things on the net... but today I fell upon two of these things in a row.

http://www.logogle.com/ggl.php?hl=ja&lo=SRK

and
http://webpages.mr.net/bobz/ttyquake/

don't look at them unless you are hopelessly jobless ;-)

Tuesday, July 26, 2005

Why?

Till now, I have mostly blogged about technical stuff. Today my mind is occupied with a lot of other things. This is the background:

From the last one year I was working on a large project and somewhat hidden from most of the nitty-gritties of an organization outside the problems of actual delivery of software. From the last one month, since I rolled out of that project, I am opening my eyes to some of these things. I have a few observations to make: This is probably true for any consulting firm.

  • The delivery phase is actually just one part of a very large process.
  • There is a lot of effort by a lot of people that goes in before an assignment actually comes through to the delivery stage.

I was hearing one of our senior executives talk about these matters (and a lot more things). Everything was so tangled up. Each and every decision which tries to untangle some of these things, brings with it a few more knots as well. As a whole, it is a chaotic environment. If you consider all the multitudes of things that humans are trying to do in this existence, I don't see any sort of order in this at all. It feels as though people are trying to make sense out of nonsense.

This fact leads to a more general question. Why are human beings in general creating and getting involved in all these complicated situations? What is driving humans to create problems for themselves and solve them and get stuck in this never ending chain?

Money - This is probably the answer for a vast majority but we see that beyond a certain level, it hardly matters. People sometimes take risks and are ready to lose money for something else.

Ego - This is probably one factor which overtakes money. People can go to any extent to maintain their self image. Probably this is also one of the factors driving the free software movement. But I feel this is again not the end. There is something else.

Something Else - I dont know what to call it. It involves the high level of passion exhibited by humans in whatever they are interested in. It is the infinite amount of creativity hiding inside every human, manifesting at various degrees. The push to do something new and special overflows from everyone given the conducive environment. When that push bursts out from within, neither money nor ego nor anything else can even come near it, let alone constrain it.

So, my conclusion is that we humans do what we are doing because we just can't help it. The knowledge/creativity/energy inside is trying to breakfree from all the limitations around. It is just the degree of manifestation that causes the differences between man and man.

Saturday, July 23, 2005

Communication with E.Ts - Yahoo!

This is my first experiment with ruby. Don't be too shocked! - the title is misleading. ok.. let me explain.

I was trying out the interfacing of ruby with other languages like C/C++, Java etc and wanted an example. So, I downloaded the C API (libyahoo2) for yahoo messenger with the idea of writing a wrapper for it in ruby. But I somehow couldn't get it working even after trying for almost a week after which I was too frustrated and gave up that idea. In the process, I looked at the C source code and ...hey! I said. Why not...? yes! you guessed it right! It looked as though I could write it in ruby itself from scratch!

I started off soon. Now, Yahoo has its own packet strcture to manage communication between its client and server. Or, can you say its own Domain specific language in a very crude sense? whatever. I tried to build that packet structure but with no success. The yahoo server doesn't respond at all if the packet is not proper i.e. it doesn't say that I am wrong. This situation looked as though I was trying to communicate with an extra-terrestrial entity in its own language!
It was indeed a very tricky situation.
  • You don't have tests to tell you what to expect out of your code.
  • You don't know how near you are or how far you are to the solution until you actually get the right solution.
But finally! after doing a little bit of trial and error and wishful thinking and all that, it actually talked to me! It started sending me the buddy lists, cookies and lots of things.

After that it was all normal. I generalised the packet generation and cleaned up my code. Right now I just have made of it a sort of API which can be used to write any sort of client. I have written a small CLI client with just the basic functionality of logging in and sending/receiving messages and typing notifications. Now I am thinking of writing a web-based client using ruby on rails and AJAX.

This was quite a useful experiment for me. It made me comfortable with ruby. I learnt a lot about how yahoo messenger works and in general how such asynchronous messaging works. I also recollected socket programming and multi-threaded programming and reading C code ;-).

Saturday, July 09, 2005

Stony Spells

"Take a true object-oriented language, such as Smalltalk. Drop the unfamiliar syntax and move to more conventional, file-based source code. Now add in a good measure of the flexibility and convenience of languages such as Python and Perl. You end up with Ruby. "

Don't look at my previous post and say that I am very fickle minded and keep changing languages. After all, programming languages are just ways to direct processes in a computer. As I am writing this, I am reminded of this definition from the SICP book:

"Computational processes are abstract beings that inhabit computers. As they evolve, processes manipulate other abstract things called data. The evolution of a rocess is directed by a pattern of rules called a program. People create programs to direct processes. In effect, we conjure the spirits of the computer with our spells."

The bottomline is that, I am trying to learn a new kind of spell - a spell of a precious stone.
I am just curious, people are praising ruby so much. Will try it out.
But it looks like, lisp has taken a very high place in my list of languages. By the way, I have some near-successful experiments in lisp. Will post them when they mature. Learning Ruby might actually help me go closer to lisp.
For the time-being, Ruby, here I come.

Monday, June 27, 2005

The Hard and the Powerful

I stumbled upon Lisp recently and have started fiddling around with it. It seems to be an entirely new world altogether. Being a C/C++ and now a Java programmer, Lisp looks HARD. Nevertheless, I read a lot of good things about it here, here etc.. (and some bad things as well). After struggling a bit with the various implementations of lisp available, I narrowed down to one of them, got it running on my machine and started coding some simple "Hello World"ish programs and reading this book.

I was a bit sceptical after seeing the extensive use of parenthesis and prefix notation ( One of the 'bad' things I've heard about lisp is this : Lots of Irritating Superfluous Parentheses). I almost felt that I was wasting my time on a complicated obsolete language. But I'm feeling a lot better now. I guess its just a matter of geting accustomed to it.
And maybe one more thing I miss is a good IDE with all the features like autocomplete, refactoring, etc. But that's not a fault of the language. Probably I have not come across one yet. However, thats not going to stop me from continuing with my Lisping.

One thing is for sure: Lisp definitely IS a powerful programming language.

Found this quote interesting:

"Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot."

- Eric Raymond, "How to Become a Hacker"

Saturday, June 25, 2005

The First Link

I finally decided to start voicing the gymnastics that happen in my mind. I think it is better to throw them out rather than let them rot inside. I have no idea what I'm going to spit out here. It may range from technological crap to the high philosophical truths, from my madness about music to my analysis of just maybe anything i find analysable. Let me see how this turns out to be.
I am currently reading a book on Socrates, and he was speaking about the chain of thoughts as a chain which binds/constrains the power of expression in men. Maybe thats one of the reason for the title of my blog.