Live data from Hacker News

How true hackers write JavaScript

news.ycombinator.com

161–170 of 342 posts

Re: How true hackers write JavaScript

#161
post #93

Earlier quoted context omitted.

Is this a GET request? What if my browser wants to peek ahead on some links?

If the Image is being created dynamically there won't be anything for browser to peek ahead at. Edit: I'd be more worried about repeated calls - but presumably the service being called is idempotent.

It's more the side effect of upvoting the whole thread that makes me wonder.

https://stackoverflow.com/questions/705782/why-shouldnt-data...

Re: How true hackers write JavaScript

#163
post #152

Seriously though... do you guys declare variables with var or let? I thought let was the new standard for scoping reasons. I'm not trying to start a holy war, I'm just a junior looking to learn.

let and const are good practice in code that will be transpiled, or in Node.js, but they're newish features that don't have 100% browser support yet, so they shouldn't be used if your code has to run directly in a browser.

https://caniuse.com/#feat=let

Re: How true hackers write JavaScript

#164
post #88

Earlier quoted context omitted.

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 wo…

It does seem strange if you think of it as “return the last evaluated thing from the function.” But that’s not the semantic; the semantic is “everything is an expression and expressions evaluate to a value.” Removing this behavior would make these languages less consistent. (And yes, in both Ruby and Rust not literally everything is an expression, but almost everything is.)

I agree that because of common uses of things like match in Rust it makes it consistent to also do it for functions. I don't agree that the reason why it's consistent is because a function body is an expression (though of course you have more expertise than me on this one -- and Rust does actually treat scopes much more strictly than most other languages so you could argue every scope has the smell of a function call associated with it).

Re: How true hackers write JavaScript

#165

If there's one take away from this, it is that programmers have widely differing opinions on what constitutes good code.

The spectrum seems to span from APL at one extreme, and Enterprise Java/C# at the other. This is closer to the former but still not that extreme (I personally lean toward that direction too, mostly working with Asm and C.)

Re: How true hackers write JavaScript

#166
post #152

Seriously though... do you guys declare variables with var or let? I thought let was the new standard for scoping reasons. I'm not trying to start a holy war, I'm just a junior looking to learn.

var is maximally compatible with older browsers. let and const are more tightly scoped, and that can help you write more maintainable code.

I think maintainability was not a first class concern in the writing of this script (consider the terse naming of variables), but it doesn't really matter; it's short, and you can understand it all because there's not all that much to understand. It does the job, and works everywhere.

Re: How true hackers write JavaScript

#168

https://twitter.com/triskweline/status/798443082740023296 > Valve's Steam Store renders on the server, uses ancient jQuery 1.8, loads 12 unminified JavaScripts. > It moved 3.5 billion dollars in 2015.

I'm not sure of what it's supposed to prove, who knows how many clients and how much money Steam lost because of slow loading/painting times or just plain broken JS. From experience I can tell that I gave up buying a game on Steam at least once because of broken jQuery. There are real metrics from top industry leaders[1][2] to prove that loading time has a clear impact on conversion rates. >Consider this when you nee…

What it proves is that it’s good enough to make tons of money.

You’re arguing from a hypothetical alternate reality where they could have been better off, but there’s no point in that. It’s like saying “Sure Usain bolt can run a sub 10sec 100m.... but if he’d gone into politics perhaps he’d made even more money and been twice as famous, we have no way of knowing, so how does that sub 10s 100m really prove anything about whether or not he’s fast?”

Usain bolt is fast, and that code made money. It’s just facts, accept them.

Re: How true hackers write JavaScript

#169
post #137

Earlier quoted context omitted.

> It costs almost nothing more to write "event" instead of "ev" or "removeElement" instead of "remEl", but it makes the code much more readable. No, it doesn't. Unless you're an absolute beginner, it takes you a couple of seconds to realize that in this codebase, "ev" (or "evt" or even "e") means "event". The same goes for "remEl". If that's consistent, then it's not a big deal at all. Having less characters makes co…

Having anything take a couple of seconds more to read something is by definition making something less readable. Okay so perhaps a couple of seconds doesn't matter. How many seconds does?

426.

Re: How true hackers write JavaScript

#170
post #139
post #137

Earlier quoted context omitted.

> It costs almost nothing more to write "event" instead of "ev" or "removeElement" instead of "remEl", but it makes the code much more readable. No, it doesn't. Unless you're an absolute beginner, it takes you a couple of seconds to realize that in this codebase, "ev" (or "evt" or even "e") means "event". The same goes for "remEl". If that's consistent, then it's not a big deal at all. Having less characters makes co…

>Having less characters makes code more readable (or rather "scannable") as well, it's just another tradeoff. Only to a point, otherwise minified js would be more legible than plain source. It takes "a couple of seconds" to scan the codebase and find out what el or ev refer to, but it would take zero seconds if they were just called "event" or "element."[0] There's no gain in readability from shaving off one or two c…

Of course, up to a point. The same goes for very long but extremely descriptive variable names. Hence, it is a tradeoff.
Post reply on HN