Live data from Hacker News

Wat

destroyallsoftware.com

11–20 of 103 posts

Re: Wat

#11
post #3

This is incredibly funny, but does anyone know why the interpreter makes such bizarre decisions? Why wouldn't it be preferable to just throw up errors?

The Ruby stuff apparently isn't bizarre. From what I've read, Ruby creates variables as it encounters an assignment to them when parsing the code. So, when you have

   a = a
in your code, Ruby creates the variable a before it ever tries to actually execute the assignment. If later, when it has finished parsing everything, and starts executing, that statement fails because b is not defined, you still end up with variable a being defined, and since it has not had anything successfully assigned to it, it has a value of nil.

The JavaScript stuff, I think, comes from operator overloading. The plus operator is overloaded to allow adding strings to concatenate them, and it will do type conversion to get compatible types, so "wat"+1 results in the 1 being converted to a string, and then the strings are concatenated. Since the minus operator is not so overloaded, "wat"-1 instead is treated as numerical subtraction. JavaScript allows string to be used as numbers, so "123"-1 gives 122. However "wat" is not a string that represents a number, so gives NaN when forced to be treated as a number, and "wat"-1 is thus NaN.

Re: Wat

#12
post #3

This is incredibly funny, but does anyone know why the interpreter makes such bizarre decisions? Why wouldn't it be preferable to just throw up errors?

[deleted]

Re: Wat

#19

Does anybody knows which is the javascript interpreter he is using on the screencast?

It's jsc (comes with Webkit) - it's present on Mac OS X by default in

/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc

You can just do:

sudo ln /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc /bin/jsc

To be able to invoke it directly from the command line.

Post reply on HN