9 ms·
Wat
- chetan51 15y agoWAT
- Karunamon 15y agoWat.
- liquidchaz 15y agoWat?
- JosephHatfield 15y agoWat? Isn't that somewhere in Cambodia?
- angli 15y agoThis 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?
- Tashtego 15y agoWelcome to the world of JavaScript. This response is NaN.
- ajross 15y agoJavascript was a rush job. And the ECMA spec was needed early due to industry pressure. So where perl and (to a lesser extent) python were able to just bury their early goofs in a pile of incompatible versions bumps, Javascript had its encased in the proverbial carbonite of an international standard. Which is sad, really, because in a lot of other ways it's the cleanest scripting language of its generation.
- getsat 15y agoFor more sadness, see: http://wtfjs.com http://wtfjs.com Fun fact: the creator of Javascript posts on HN. Maybe he'll answer your question.
- tzs 15y agoThe 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.
- deleted 15y ago[deleted]
- lucisferre 15y agoThanks for that. I was curious the reason, it seems obvious though after an explanation.
- deleted 15y ago[deleted]
- lmkg 15y agoJavaScript has a strong design principle of not throwing errors for syntactically valid constructs. The most common way it accomplishes this is through gratuitous use of implicit type conversions. It does a lot of implicit string conversions, even on things that you would think of as error codes, like undefined or NaN. 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.
- runT1ME 15y agoI wish there was some technology that could take a bunch of code and warn you of common errors before having it execute and 'noisily crash the page it was on'. Maybe someday...
- ricardobeat 15y agoSarcasm doesn't work here. It's not reasonable to expect proper testing or usage of an IDE by ordinary citizens authoring HTML. Specially in 1996.
- jrabone 15y agoYeah, I mean, it's not like they had compilers back then. Savages.
- qqqqqq 15y agoHilarious! This reminds me of a StackOverflow question which asked the users for the weirdest language quirks they could think of. I laughed pretty hard at that too.
- franciscoapinto 15y agoThis is a repost, but whatever. Hopefully people who haven't seen it before will enjoy it.
- libraryatnight 15y agoEven with my limited programming knowledge I laughed a lot through this.
- felideon 15y agoAt work people always tell me "You IT guys are all so funny."
- murphysbooks 15y agoI laughed so loud I scared myself. Now, I know why my wife looks at me funny.
- stevenou 15y agoWow, I laughed so hard I cried! This is hilarious...
- nekomata 15y agowow, you must be the best hacker ever congrats
- stevenou 15y agoI understand the downvotes since this is HN and you people don't like useless comments here. But I simply thought it was very funny. No need to be mean here.
- billpatrianakos 15y agoFor the record, the downvotes aren't to be mean. We just don't want this turning into a Reddit clone and/or fill the comments with run-of-the-mill comments you'd see on any PHPbb forum. 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.
- stevenou 15y agoThanks for the reply. Perhaps I was unclear. I completely understand the downvotes - that's why they're on the site. But I thought the "wow, you must be the best hacker ever congrats" comment was unnecessary and mean-spirited.
- hchinchilla 15y agoDoes anybody knows which is the javascript interpreter he is using on the screencast?
- jarito 15y agoLooks like something that comes as part of Webkit: http://trac.webkit.org/wiki/JSC http://trac.webkit.org/wiki/JSC
- GuiA 15y agoIt'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.
- hchinchilla 15y agoThanks, I'll look how to get this working on linux.
- gpmcadam 15y agoAlternatively, you could use Rhino Shell (https://developer.mozilla.org/en/Rhino_Shell https://developer.mozilla.org/en/Rhino_Shell) - it even supports tab completion!
- mbq 15y agoAt least Arch has `js`package which gives you js command to obtain JS shell; in fact it is just Mozilla's SpiderMonkey. Anyway, the best option for "standalone JS" is node, mainly because it has a sane way of importing code from other files.
- betterth 15y agoMy Chrome install on Windows has the same thing. I push ctrl+shift+c to load the developer tools, and click on console and it's a very similar tool to what he was using.
- greenpizza13 15y agoThis is hilarious!
- brudgers 15y agoQuicktime? We don't need no stinking web standards!
- program 15y ago$ php -r '::' Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM Wat
- dangrossman 15y agoPffth, you just need to learn Hebrew before you learn PHP. That says "double dot twice".
- eridius 15y ago$ 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
- chrisrogers 15y agoThis was introduced by Zend, which is israeli. Thus the Hebrew.
- jfarmer 15y agoI first saw that error in a pre-Google world. It took a few days for me to figure out what it meant.
- overshard 15y agoThis is the greatest video ever.
- tylerritchie 15y agoWhat presentation software is he using? Is he just jumping from his slide deck into a shell?
- garybernhardt 15y agoIt's Keynote. I recorded those sessions as screencasts, then sliced them into tiny pieces so I can advance them perfectly with my talking. There are 37 slides in that four-minute talk. In some cases, the slices are only two or three frames long.
- tylerritchie 15y agoAh that makes sense, thank you. I may steal that idea for future talks with R. Though, just embedding a shell in a slide deck would be very nice.
- garybernhardt 15y agoI like the sliced screencasts because they're so repeatable. I practice my talks a lot, and I can get the timing down perfectly because it's always the same. Highly recommended. :)
- chaz 15y agoThe preparation really shows -- great job. Ability to present really well is a critical skill for anyone with a product head.
- flatline 15y agoGuess I'm not a hacker? It's like watching a rerun I've seen twice over with the laugh track turned up to 11 (just to clarify, someone said it was a repost but I haven't seen it before).
- garybernhardt 15y agoThere's no laugh track; that's the audience.
- deleted 15y ago[deleted]
- dmansen 15y agoYeah count me in the "not a hacker, I guess" crowd, this stuff isn't very funny.
- Zancarius 15y ago"Wat" at the start really turned me off. I realize that was probably (?) part of the shtick, but it's one misspelling in particular that really drives me nuts. Real hacker humor is fairly dry (the story about magic comes to mind); this felt more like script kiddie-level humor. I can see valid points (and humor) raised with the Ruby interpreter, but the delivery could have been better--at least more adult-ish. 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.
- billpatrianakos 15y agoRight. It was marginally informative, the meme pics were chuckle-in-my-head worthy but what really got me laughing was that it's on the front page of HN. Its so sad you have to laugh to keep from crying. Anyway, guess I'm not a hacker either.
- 15y ago
- nodesocket 15y agoInterestingly the results from jsc, are different from node.js: ----- jsc ------ [] + [] > [] + {} [object Object] > {} + [] 0 > {} + {} NaN ------ node.js ------ > [] + [] '' > [] + {} '[object Object]' > {} + [] '[object Object]' > {} + {} '[object Object][object Object]'
- lftl 15y agoI don't even understand what the last node.js entry is. Is that an array with two objects? Also, I'm on an old version of node, but my output matches jsc.
- udp 15y agoThe `toString` of two Object-s concatenated, I think.
- esrauch 15y agoThe other reply is right, to clarify String({}) === "[object Object]" 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.
- Cushman 15y agoThis appears to be a peculiarity of the REPL implementations, not a difference between V8 and JSC. d8 (and the Chrome console) behaves the same way as jsc, while you can make d8 and jsc behave the same as the node REPL by wrapping each statement in parentheses: 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.
- garybernhardt 15y agoNo, it's more subtle than that. By wrapping in parenthesis, you're making it an expression. When you just say "{}+[]" in e.g. Chrome, the first {} is parsed as a block. So what you see printed is the result of "+[]", which is 0. This is why {}+[] is not equal to {}+[] without parens. This may also be why Node gives different results; I'm not sure. 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.
- nabilt 15y agoThe presenter also has a catalog of screencasts here https://www.destroyallsoftware.com/screencasts https://www.destroyallsoftware.com/screencasts. Haven't listen to them, but the topics look interesting.
- eggbrain 15y agoWow, this title suffers from some serious editorializing. What's next, "10 ways to know if you are a hacker? (cracked.com)"
- famousactress 15y agoI feel like we've been suffering extra-much from this effect lately...
- deleted 15y ago[deleted]
- baddox 15y agoHow does this have anything to do with a sense of humor specific to hackers? Don't all professionals enjoy jokes about their field?
- abahgat 15y agoThat is exactly what I was wondering: what you say must be true, but I could not find any equivalent of what you see here for any other profession. But maybe it is just because I write code for a living...
- bgarbiak 15y agoWhat's the "correct" ("less funny"?) result of 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).
- Anderkent 15y agoA TypeError.
- weavejester 15y agoThat's probably one of the more logical examples. I'd have expected an exception from any other language, though (Javascript I know doesn't tend to type error).
- antoncohen 15y agoWell, .join(x) joins an array into a string, with x as the separator. First of all what does Array(16) make? Effectively it should make an array with null 16 times. Now, JavaScript seems to think null is a blank string, a string with the text 'null', or a zero depending on the context. 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]) ''
- orbitingpluto 15y agoArray(16) That's 15 commas, not 16.
- tlrobinson 15y agoHandy way to make some padding: function pad(n, c) { return Array(n+1).join(c); } // pad(6, "-") === "------"
- baby 15y agoif you laugh, you know ruby.
- iapetos 15y agowhy do i have to signup to know who much it costs to subscribe. I think it should be apparent on the home page. EDIT ok my bad it was mentioned on the screencasts homepage
- garybernhardt 15y agoIt's on the front page, but at the bottom. DAS is a small one-man business, so I did the design myself (and I'm not a good designer). Sorry about that. :)
- jrockway 15y agoI guess you had to be there. I can see why someone might find this funny, but honestly, nothing is that funny. Some behavior in Javascript is surprising, but not that surprising.
- marshray 15y agoIf you've ever gone through a phase (or a graduate degree!) of thinking deeply about programming language design, you might, as I do, find Javascript's expression evaluation behavior to be just about the funniest thing around.
- jrockway 15y agoI have but I don't. Javascript was designed to reduce programmer-visible errors at the cost of making it nearly impossible to write a correct program. At that goal, it succeeds, and [] + {} being NaN makes perfect sense under those constraints.
- there 15y agothat weird behavior of javascript can actually be used for xss attacks, by being able to assemble strings. for example: (![]+[])[+!+[]] produces an "a". https://news.ycombinator.com/item?id=1153383 https://news.ycombinator.com/item?id=1153383
- jrockway 15y agoBut of course, anyone that actually wants to protect against XSS attacks won't allow user input to be evaluated. If they did want to allow user-supplied Javascript, they wouldn't blacklist, they would whitelist (by parsing the user-supplied script and using the AST to emit only whitelisted operations).
- glhaynes 15y agoHave I been pronouncing "wat" wrong all this time? I just assumed it was like "what" but ... not.
- gnarbarian 15y agoNo. I'm with you man. The way he said it was seriously bugging me. At the same time I couldn't justify my annoyance with an alternative pronunciation that made sense. Perhaps some memes should never be vocalized.
- farnsworth 15y agoI guess this is where we all complain about HN finally jumping the shark and turning into Reddit.
- conbtl 15y agoCongrats to all of you who laughed. You are all great hackers. I don't find this remotely funny.
- nessus42 15y agoI think that a hacker would also realize that the title makes no claim whatsoever about the hacker status of those who don't laugh.
- phzbOx 15y agoFor some reason, what I find the most hilarious here is reading the extremely serious HN comments. It's a weird contrast.