Wat(destroyallsoftware.com) |
No, I wasn't one of the ones who downvoted you and no, I'm not trying to be mean. There used to be times I wondered why an innocent comment of mine was downvoted and thought I'd just let you know instead of leave you hanging.
$ php -r '::'
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
Wat $ php -r '::'
Parse error: parse error in Command line code on line 1
How'd you get the weird error?Edit:
Hrm, if I try it on my DreamHost account, I get something more similar to yours:
$ php -r '::'
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in Command line code on line 1----- jsc ------
[] + []
> [] + {}
[object Object]
> {} + []
0
> {} + {}
NaN
------ node.js ------ > [] + []
''
> [] + {}
'[object Object]'
> {} + []
'[object Object]'
> {} + {}
'[object Object][object Object]' d8> ([] + [])
d8> ([] + {})
[object Object]
d8> ({} + [])
[object Object]
d8> ({} + {})
[object Object][object Object]
So I believe this is merely erroneous behavior of the console, not a weirdness of JavaScript itself.I didn't mention any of this in the talk (it would've killed the flow ;). Instead, I glossed over it and interpreted the syntax as any sane programmer would.
Also, I'm on an old version of node, but my output matches jsc.
I think the actual video was a little misleading, [] + {} == the string "[object Object]" not an object. The square brackets are just part of the tostring method and are unrelated to the square brackets of arrays.
But maybe it is just because I write code for a living...
(![]+[])[+!+[]]
produces an "a"./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.
I suppose if you are a WebKit-only developer, this utility could have many useful applications.
Perhaps some memes should never be vocalized.
That's 15 commas, not 16.
function pad(n, c) { return Array(n+1).join(c); }
// pad(6, "-") === "------" Array(16).join("wat" - 1) + " Batman!"
?Empty strings separated with NaNs look perfectly logical to me (I'm a JS guy though, so, well, bear with me).
The first thing it should do is TypeError that null is not a string. Or don't join null fields because there is nothing there.
If is does convert null to '', then it should TypeError on string - int. If it is not going to TypeError it should do something sensible, like slice the string
> Array(16).join("wat".slice(0,-1)) + " Batman!"
'wawawawawawawawawawawawawawawa Batman!'
I think the correct thing would be to TypeError in two different places. Or change the language so things that don't error actually work. Returning a string with NaNs in it will just lead to uncaught errors. If it actually returns something it should probably be ' Batman!'.JavaScript nuttiness:
Now it's zero:
> null + 1
1
Now it's "null": > null + "text"
'nulltext'
Now it's a blank string: > [null, null, null].join()
',,'
Python errors when things don't make sense, and forces you to make them make sense:If it doesn't work, error:
>>> "wat" - 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'int'
Can't join None into a string: >>> ','.join([None, None, None])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, NoneType found
Convert None to a string if you want: >>> ','.join([str(i) for i in [None, None, None]])
'None,None,None'
But it makes more sense to drop the None: >>> ','.join([str(i) for i in [None, None, None] if i])
''EDIT ok my bad it was mentioned on the screencasts homepage
JavaScript went down the path of being a "forgiving" language because it was intended to provide "extra" (non-core) functionality, under a lot of environments, in the hands of non-experts. It made sense at the time that it should fail silently rather than noisily to not crash the page it was on. It also tried to help amateurs who just banged on code until it did what they wanted, by generally doing something rather than nothing, and by trying to infer intended behavior from undisciplined code. It was never intended to make large-scale or robust applications, so it didn't make decisions that would facilitate that use-case.
Maybe someday...
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.
Fun fact: the creator of Javascript posts on HN. Maybe he'll answer your question.
I managed about halfway through. I did have the audio turned off, so I'm assuming I missed out on some of the redeeming qualities it may have had. Given the liberal usage of "wat" throughout what I did watch, I suspect that my gut feel is likely correct.
Anyway, guess I'm not a hacker either.
I think is simply laughing at absurdity: the gulf between intention and actuality. We have quite a bit of that.
I guess it's an amusing bit of sleight-of-hand, but using it to mock JavaScript seems, I don't know, tasteless. Doesn't it have enough problems without inventing more?
To clarify, I thought the first part of the talk was funny. Here's a weird bit of Ruby. Hah! Here's a weird bit of JavaScript. Hah! Here's some JavaScript to make you think it's weird in a way it actually isn't! Uh, okay? Just don't see what's funny about that, I guess.
To address your particular concern which I feel is somewhat misplaced: I think it would be more pertinent to classify individuals like myself and the others who have complained about the delivery of this particular piece as suffering from less patience, especially with the usage of "wat" throughout. There are reasons for this, and it likely depends on an individual's preferences, how one feels about the (mis)usage of language, or the (ab)use of memes to attempt the creation of a witty informational exchange. Note: I realize that I'm probably just slightly outside the target demographic of this video, which probably appeals more to individuals who are in their mid-twenties or younger, and I'm fully aware of this fact.
I apologize if I personally came off as a pompous whiner. This particular misspelling of "what" is a personal pet peeve that drives me absolutely insane, and it greatly reduces my mental perception of an item's quality (or the quality of an individual's speech). I suppose other complaints probably derive from its delivery as a meme-inspired video, which probably appeals to younger audiences as I've mentioned.
In other words: There are legitimate gripes about this form of video. I've seen similar ones that were indeed humorous, but they had a fantastic delivery that was well thought-out. Including a dozen absurd pictures that appear to be sourced from sites like Imgur with "WAT" emblazoned on them does not appeal to everyone, and I don't think it's useful to criticize others' opinions of this video as sorely lacking in humor as "sad" simply because we all have greatly different tastes and preferences. Moreover, these tastes and preferences are malleable; something you found hilarious when you were 22 might be head-shakingly awful by the time you're in your 30s.
I suspect this video is one of these. Save it and watch it again in ten or fifteen years.
Also, if you want a good example to serve as a useful benchmark for classical "hacker humor," I present to you this piece: http://catb.org/jargon/html/magic-story.html
And for the record, I'm 25 so either I'm really mature or I have no sense of humor. The jury is out. I'm definitely still not hacker though as I watched it again and still barely chuckled.
Regardless of what others might feel, you're absolutely right. The title had about as much redeeming value as the video. :)
I'll join you in the non-hacker, no-humor camp. This is particularly true since my inner grammar Nazi finds the abuse of "what" to be abhorrent...