Thursday, September 11, 2008

Shortest* Javascript Code that prints its own Code!

This is one of the challenging tasks for any programming language:
Write a code that prints itself on the terminal!
To make it more interesting… code it short!

I took a shot at javascript and came up with the following code. If you can come up with shorter code, DO POST AS COMMENT!

Lets see who’s short&smart!

The Code (177 chars, tested on FF3):

var dq='"';var q="'";var s='document.write("var dq="+q+dq+q+";var q="+dq+q+dq+";var s="+q+s+q+";"+s);';document.write("var dq="+q+dq+q+";var q="+dq+q+dq+";var s="+q+s+q+";"+s);

Your turn now… I’m waiting!

Monday, September 8, 2008

Coolest Programming Convention Ever!!!

Really don’t know how many of you actually heard of this...

This coding convention is really cool:

It goes like this: For equivalence statements, keep the constant on the left side.

Eg. a == 3; //Not Good

3 == a; //Gr8!

How it helps???? It will help you in situations where you "mistakingly" used a "=" inplace of"==".

a = 3 compiles to true

While, 3 = a generates a compile time error!!!

Wow!! Isn’t it!