Live data from Hacker News

How true hackers write JavaScript

news.ycombinator.com

21–30 of 342 posts

Re: How true hackers write JavaScript

#24
post #4

That might be one of the most readable pieces of code that I've ever read.

Really? It has horrendous naming and it isn't even using es6

function byClass (el, cl) { return el ? el.getElementsByClassName(cl) : [] }

const byClass = (el, cl) => el ? el.getElementsByClassName(cl) : []

Re: How true hackers write JavaScript

#26
post #4

That might be one of the most readable pieces of code that I've ever read.

Really? Plenty of needlessly abbreviated function names IMO. At a quick glance is it immediately obvious what posf or arem are without looking into the context in which they're being used? Don't get me wrong it's a nice piece of code but super-readable it isn't.

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

Re: How true hackers write JavaScript

#28
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.

Re: How true hackers write JavaScript

#29
post #4

That might be one of the most readable pieces of code that I've ever read.

Really? It has horrendous naming and it isn't even using es6 function byClass (el, cl) { return el ? el.getElementsByClassName(cl) : [] } const byClass = (el, cl) => el ? el.getElementsByClassName(cl) : []

How does es6 improve readability in this case? It barely removes `{}` and replaces very clear word `function` with `const` that in most languages is associated with constant values, not with functions

Re: How true hackers write JavaScript

#30
post #4

That might be one of the most readable pieces of code that I've ever read.

Really? It has horrendous naming and it isn't even using es6 function byClass (el, cl) { return el ? el.getElementsByClassName(cl) : [] } const byClass = (el, cl) => el ? el.getElementsByClassName(cl) : []

It was almost certainly written long before ES6 was widely supported.
Post reply on HN