Live data from Hacker News

How true hackers write JavaScript

news.ycombinator.com

71–80 of 342 posts

Re: How true hackers write JavaScript

#71

Thanks for sharing this nice bit of code; we always learn from examples, we should see more of this. I feel the naming is too short, things are just a little too specifically compact and slightly cryptic ... almost like the author is trying to say something ... I've never said this before about code ... but I think that code is 'smug'! Like odd facial hair, or one of those valley-specific t-shirts ... the code trying…

Really? It just looks compact and efficient to me.

Re: How true hackers write JavaScript

#72
The authors is quite lazy or cannot type fast enough, so he has to create all those cryptic abbreviations: `rks` for `ranks`, `unv` for `unvote`, etc. Which makes it really hard to read.

But it's especially the inconsistent use of camelcase in function names than makes me think it's pretty amateurish.

Re: How true hackers write JavaScript

#73

Thanks for sharing this nice bit of code; we always learn from examples, we should see more of this. I feel the naming is too short, things are just a little too specifically compact and slightly cryptic ... almost like the author is trying to say something ... I've never said this before about code ... but I think that code is 'smug'! Like odd facial hair, or one of those valley-specific t-shirts ... the code trying…

Exactly, those function names hurt my brain:

remClass -> does it hurt to write removeClass ?

what is vis, ind, posf? I shouldn't have to decipher the function to figure out what its name might mean.

Hacker? no. Smug? yes

Re: How true hackers write JavaScript

#74
post #70

function hidestory (ev, el, id) { for (var i=0; i That 3 there is the problem with “simple” JS. It’s tightly coupled to the HTML but they live in completely different places. On a side note this 3 should be at least assigned to a variable with a meaningful name.

hidestory() is not even used anywhere ; why is it here for? Debugging?

Re: How true hackers write JavaScript

#78
post #37

Earlier quoted context omitted.

For the record, jQuery 3.3.1 (production, normal) is at 30kb [1]; if you don't want effects (production, slim), you can get it for less than 24kb [2]. For the value it provides, that does not sound "too big" to me. [1]: https://code.jquery.com/jquery-3.3.1.min.js [2]: https://code.jquery.com/jquery-3.3.1.slim.min.js

In contrast, hn.js only weighs 2.1kb and contains all the business logic.

And it isn't even minified. So if there would be a problem in production it would be easily debuggable.

Re: How true hackers write JavaScript

#79
post #72

The authors is quite lazy or cannot type fast enough, so he has to create all those cryptic abbreviations: `rks` for `ranks`, `unv` for `unvote`, etc. Which makes it really hard to read. But it's especially the inconsistent use of camelcase in function names than makes me think it's pretty amateurish.

Yeah, just looks like a grease monkey script I would have banged out a decade ago in about an hour. Nothing wrong with that. It's far more interesting how much people are reading into this code haha. It was clearly not written to be read by us today IMHO.

Re: How true hackers write JavaScript

#80
This code would be a bit shorter and simpler if it dropped support for old browsers (specifically, Internet Explorer).

Some examples:

The functions hasClass, addClass, and remClass could be replaced by Element.classList [0].

Another one is remEl, which can be replaced with a direct call to ChildNode.remove() [1].

I was going to give more examples, but I don't feel like rewriting the whole script.

[0] https://developer.mozilla.org/en-US/docs/Web/API/Element/cla...

[1] https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/r...

Post reply on HN