Live data from Hacker News

How true hackers write JavaScript

news.ycombinator.com

51–60 of 342 posts

Re: How true hackers write JavaScript

#51
post #11

This is neat (how the up/downvote onclick handler sends the info to the server). new Image().src = el.href; Where href looks like this: vote?id=xxxxxxxx&how=up&auth=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy&goto=item%3Fid%3Dzzzzzzzz#wwwwwwww

Maybe it's neat but this is not how anyone would write it today. This is the legacy code still left from the time before ajax was invented.

There's also an XMLHttpRequest wrapper for when they care about the response.

This is used for write-only GET requests (with graceful fallback when JS is disabled since those are plain anchor elements).

Re: How true hackers write JavaScript

#52
post #22

To me this looks more like transpiler output ...

It would if the variable names were all a,b,c. But they're not, they are almost Polish Notation. There's a all right, but fn, cl, tag for callbacks classes and tags. Also n and m for integers in a range and x for iterable integers.

This is the work of someone with a ton of experience. You take 10 minutes to look at the code and understand it, then you are groking complex ideas and operations quickly. I'd love to work with whoever wrote that code.

Re: How true hackers write JavaScript

#56
post #50
post #41

function aeach (fn, a) { return Array.prototype.forEach.call(a, fn) } Does this win anything over using forEach directly?

This function could be used to iterate over the `arguments` array like object, but I do not think it is used for that purpose here.

It's used to iterate over HTMLCollection objects here.

Re: How true hackers write JavaScript

#57

In most places this code would never pass a code review and would be considered plain unacceptable. I guess I'd prefer some place where this code style is the norm.

Go into academia. You'll receive no code review, and you'll deal with pretty bad code, but you'll be free to write however you want as long as it works and can be published.

Re: How true hackers write JavaScript

#58
post #48

Earlier quoted context omitted.

Well, I disagree. It is abbreviated, but since the whole file is self-contained and the definitions are put at the beginning, there is enough information to infer the function's semantics without being excessively specific. I think well defined organization of abstractions is an often overlooked but surprisingly effective way to achieve readability

> there is enough information to infer the function's semantics without being excessively specific You mean you can just read the function definition to see what it does?

He doesn't like being excessively specific with his writing I guess. Plus it makes you sound more like an engineer when you speak like this.

Re: How true hackers write JavaScript

#59
post #11

This is neat (how the up/downvote onclick handler sends the info to the server). new Image().src = el.href; Where href looks like this: vote?id=xxxxxxxx&how=up&auth=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy&goto=item%3Fid%3Dzzzzzzzz#wwwwwwww

Maybe it's neat but this is not how anyone would write it today. This is the legacy code still left from the time before ajax was invented.

It is strange. I wonder if it's an approach that lets duplicate vote attempts get automatically responded to by the webserver cache rather than passing through to be detected computationally at the application server level, which would also involve a DB call.

Conceivably this would make the architecture more robust against vote-spamming attacks, and the approach would also provide an enhanced version of this benefit if using an external caching reverse-proxy service like CloudFlare or similar (though I believe HN does not use CloudFlare).

This is complete supposition on my part.

Post reply on HN