Live data from Hacker News

How true hackers write JavaScript

news.ycombinator.com

271–280 of 342 posts

Re: How true hackers write JavaScript

#271

I'm not sure if this was linked fatously, but this is actually pretty good JS. - All functions - The functions are simple and decomposed into smaller functions - No usages of "this" (except one necessary one in an event handler) - No ham fisted attempts at doing OOP with JS Only complaints really are naming and code style is overly compact which would potentially make it harder to understand, but in this context I th…

should be using fat arrow functions.

Re: How true hackers write JavaScript

#272
OP here, looking at the vote function, I learned something new today - this code:

  new Image().src = el.href;
will make image request to server with any params from href so you can process the voting stuff. Nice one.

Re: How true hackers write JavaScript

#273
post #86

Earlier quoted context omitted.

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.

> So you would like to work a place with no code review? How does this follow from my statement?

Sorry if I misunderstood.

Re: How true hackers write JavaScript

#274

Am I the only one who thinks this is unreadable? var on = !afind($(id), collapsed()); (on ? addClass : remClass)($(id), 'coll'); where function afind (x, a) { var i = apos(x, a); return (i >= 0) ? a[i] : null; } where function apos (x, a) { return (typeof x == 'function') ? posf(x,a) : Array.prototype.indexOf.call(a,x) } where function posf (f, a) { for (var i=0; i

+1,000. The best programming advice I ever got was to write code for other people to read (and understand at a glance), not for the machine to execute. This code is the precise opposite of that.

[deleted]

Re: How true hackers write JavaScript

#275
post #118

Um, is this supposed to be a criticism? Because this is MUCH better than sites loading megabytes worth of scripts to do nothing more than render text, have dozens of floating elements everywhere, auto playing videos that follow you, "use our app" buttons, etc... JS is the assembly of the web, do you also criticize games written in assembly?

>JS is the assembly of the web, do you also criticize games written in assembly? No it isn't, any more than C++ is the assembly of your operating system. Assembly has the terseness that it does because of constraints that javascript doesn't have -- this javascript looks the way it does because the author wanted it to look like lisp code, not because it has to.

Assembly, used this way, just means “the words that create action at the layer below which you cannot go”. Also referred to as “metal”.

Depending on where you are starting that could be JavaScript, or it could be Basic, or any of a number of things. In the browser it’s JavaScript.

This only makes sense if you can see that there are machines within the machines, within the machines.

Re: How true hackers write JavaScript

#276
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

Yes, and it reminds me also of Unix shell commands.

Re: How true hackers write JavaScript

#277
post #98

I don't understand why people are dissing this. It does what it's designed to do, and fills a specific need for one website. It's not there as a teaching aid, nor is it meant to be shared for other people to use elsewhere. Not everything has to be gold-standard code full of perfect variable names, extensive comments and good whitespacing. If you have a day job that isn't primarily writing code, and/or you are likely…

Yes exactly. KISS people!

Re: How true hackers write JavaScript

#278

Um, is this supposed to be a criticism? Because this is MUCH better than sites loading megabytes worth of scripts to do nothing more than render text, have dozens of floating elements everywhere, auto playing videos that follow you, "use our app" buttons, etc... JS is the assembly of the web, do you also criticize games written in assembly?

macOS just notified me that one tab in Safari was using so much memory it was threatening performance of my laptop. The website in question? https://idioms.thefreedictionary.com/ It was close to 2Gb RAM usage. Bunch of ad-tracking stuff, I assume, as Firefox and its related processes seem to be using less than 1250mb with 6 tabs open, including the site mentioned in 2 tabs. My firefox has uBlock origin installed. See…

There is a certain irony about a dictionary web-page using 3 times more memory than it takes to store the entire Oxford English dictionary (and accessory publications), that is undoubtedly more complete.

Re: How true hackers write JavaScript

#279

Um, is this supposed to be a criticism? Because this is MUCH better than sites loading megabytes worth of scripts to do nothing more than render text, have dozens of floating elements everywhere, auto playing videos that follow you, "use our app" buttons, etc... JS is the assembly of the web, do you also criticize games written in assembly?

> Because this is MUCH better than sites loading megabytes worth of scripts to do nothing more than render text, have dozens of floating elements everywhere, auto playing videos that follow you, "use our app" buttons, etc...

False dilemma. Code can be concise and readable.

> JS is the assembly of the web

No. Assembly is supposed to have a virtually one-to-one correspondence with machine code. JavaScript is far from that. It is a higher-level language.

> do you also criticize games written in assembly?

I would indeed criticize someone writing a game in assembly if an alternative was available.

Re: How true hackers write JavaScript

#280
post #172

Earlier quoted context omitted.

Well using divs would at least make you able to group the elements semantically so you could remove a single node rather than having a for loop which removes exactly three nodes. This would be significantly simpler in my opinion. And it would be less fragile since now you can redesign everything inside this node without the JavaScript breaking.

Agreed. But getting divs to do what you want has also gotten considerably easier in the last 10 years. It used to be a lot more work/boilerplate to get a consistent div-based layout across all browsers down to IE 6. As for the redesign, the total amount of code (HTML/CSS/JS) you’d need to touch is still small. Do web designers still exist that only do HTML/CSS but no JS?

> Do web designers still exist that only do HTML/CSS but no JS?

I hope so, given that most websites (as opposed to web apps) in existence should not need JS for core functionality.

Post reply on HN