Live data from Hacker News

How true hackers write JavaScript

news.ycombinator.com

81–90 of 342 posts

Re: How true hackers write JavaScript

#81
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) : []

Probably not worth setting up a babel transpiler for that small amount of JS tbh

Makes supporting older browsers a lot easier

Re: How true hackers write JavaScript

#83
post #42

This style is very similar to one which is used by expert C programmers, it seems that most people that write like this have had experience writing parsers and compilers too. It's not their fault that most people don't just think purely in terms of function composition :P

I'm sure the code works very well for its intended purpose, but I'm kind of wary of the idea that using obscure abbreviations like 'posf', 'arem', 'vis', 'ind' etc. makes you "expert hacker".

I don't agree that code should always be designed to be perfectly readable by outsiders. If such abbreviations works for the people who have to maintain the code, more power to them. But I disagree than this is somehow proof of superior skill.

Re: How true hackers write JavaScript

#84

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.

"Compact" (abbreviated) names are negligibly more efficient when machines read them, and they're wildly less efficient when humans read them. Code is read many more times than it's written, so it doesn't make sense to optimize for fewer keystrokes when typing the code.

This is especially true with modern IDEs that autocomplete everything.

Re: How true hackers write JavaScript

#85
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?

It is probably called in an onclick=“” in the HTML somewhere

Re: How true hackers write JavaScript

#86

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.

So you would like to work a place with no code review? You will be happy to hear that many many workplaces have no code review at all.

Re: How true hackers write JavaScript

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

Hard to read? The sum total of the script fits on 2-3 pages at most, no single function exceeds about 10 lines, if you have trouble reading and reasoning about that code then something is wrong.

Re: How true hackers write JavaScript

#88
post #36
post #29

Earlier quoted context omitted.

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

It removes the brackets and the return keyword, const is in fact a constant but this not ES6 it is just doing a function expression instead a function declaration (you create a const variable and assign an anonymous function to it instead of using the keyword 'function') This is used for readability and to avoid hoisting that can be confusing.

Given that brackets and the return keyword (and the function keyword!) are core parts of functions (a scope and a value to return to the caller), I would argue that removing these key parts of a function makes it harder for someone not familiar with ES6 to see that it is a function.

This reminds me of Ruby's return-the-last-evaluated-thing-in-a-function semantics (which sadly Rust copied). Having to type one extra word is not such a burden that you should add cognitive overhead each time someone not intimately familiar with the language has to read your code.

If the argument is that only ES6 experts should only ever have to read or write ES6 code, then I would argue that any syntax argument is pointless because only experts can comment on a languages syntax -- and thus COBOL objectively has the best syntax and you cannot disagree unless you are a COBOL expert.

Re: How true hackers write JavaScript

#89
post #44
post #4

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

It seems some of the one-liners are simply renaming JavaScript built-ins like forEach to aeach and slice to acut. Maybe this is to make it look more like the Lisp backend? But taken on its own it does not really improve readability.

No, it is because some array-like objects like node lists actually aren't Arrays and don't have those functions in their prototype.

Re: How true hackers write JavaScript

#90
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) : []

You're still returning a live HTMLCollection or an Array.

It's still bad code. Using newer syntax to do the same thing didn't actually improve anything.

Post reply on HN