Live data from Hacker News

JavaScript for Impatient Programmers

exploringjs.com

101–104 of 104 posts

Re: JavaScript for Impatient Programmers

#101

My "real" advice for impatient programmers: just start programming, and every time you encounter a problem google it. Don't know how to setup node.js? Google should lead you to `npm init` or a starter. Getting some weird syntax error? Google it. Once you learn the basics, want to do X? Google it and determine a) how to do X, or b) if X can't be done / is bad practice. Just by diving head-first into whatever you're tr…

npm init is not involved in setting up node.

Go ogling it leads to being told to use os package managers, which do the wrong thing

Re: JavaScript for Impatient Programmers

#102

Earlier quoted context omitted.

Do you have an example of a DOM operation that is async ?

Creating a new element on the DOM, especially when it is creating a new script element. It takes non-zero time to load and parse but returns control to JavaScript immediately. So you need to wait on the element with like onLoad before calling a function in that script. There's some more instances I've forgotten. The situation is better now with promises but it was a pain in the ass just a few years ago.

Well, yeah, some DOM elements have async side effect, but they are still added to the DOM synchronously. Creating the element and loading it's content are two completely separate things.

Re: JavaScript for Impatient Programmers

#103

Earlier quoted context omitted.

Creating a new element on the DOM, especially when it is creating a new script element. It takes non-zero time to load and parse but returns control to JavaScript immediately. So you need to wait on the element with like onLoad before calling a function in that script. There's some more instances I've forgotten. The situation is better now with promises but it was a pain in the ass just a few years ago.

Well, yeah, some DOM elements have async side effect, but they are still added to the DOM synchronously. Creating the element and loading it's content are two completely separate things.

That's non-obvious to people from other languages, at least it was to me. The asynchronous nature of DOM manipulation also comes up when the DOM gets large and you naively try updating elements querying by tag or class.

It's idiosyncrasies aren't deal breakers but they're non-obvious. They also crop up once you're into medium complexity code. At the level of simple/trivial code machines and JavaScript engines are fast enough to paper over naively written code. But you get to a certain level of complexity and you get bit by some colored function issue or something.

It's annoying bringing something up where JavaScript is not the primary focus of the project. This is all anecdotal, there's plenty of people that might never have issues. But it was all stuff that tripped me up around 2009-10 having to write some JS after not having touched it since before you could make XHRs or manipulate the DOM directly.

Re: JavaScript for Impatient Programmers

#104

My biggest hurdle with JavaScript was getting things to happen in order. Functions can be unexpectedly colorful[0] and contortions and boilerplate is needed to deal with that. What was unintuitive to me was a lot of interactions with the DOM are asynchronous without being explicit about it. So you've got to chain a bunch of asynchronous calls together to make sure a sequence of events occur. Most other languages make…

After a year or so writing "async" code it has become natural. I now think of the real world as async. For example during Christmas I do not "poll" the door every 10 minute to see Santa clause. I simply wait until he knocks on the door and then I run the knockOnDoor callback function.

So in my mind functions did not have colors. They where "first class functions" that you could pass into another function that later called it. Now however we do have normal functions (before ES6-7), as well as async/await promise returning functions, and *function yealding generator functions.

Post reply on HN