HNHacker News
TopNewBestAskShowJobs

sloonz

6 karma · joined March 26, 2018

submissionscomments
sloonz··on Unicode character “ꙮ” (U+A66E) is being updated
> so what harm is there in one codepoint no one will ever need?

Fonts bloat (do you want a font with 1 million characters in it ? I don’t. Do you want to have to install 1000 fonts having 1000 characters each to be sure to cover all the Unicode table ? I don't).

Lots of issues for everyday programmers (how do you handle weird unicode characters in your validation code ?) potentially leading to security issues (bypassing validation rules by close-but-different characters, phishing…)

sloonz··on A brief look at async-await
The dot one line above is the better style. Change my mind.

Pasting

  check()
    .then()
in node REPL gives :

  > check()
  undefined
  > .then()
  Invalid REPL keyword

Pasting

  check().
    then()
Gives the expected result.

More generally, Javascript rules about whether a newline constitutes the end of a statement or not are pretty confusing (at least for me), so I prefer using a form that makes it explicit when a statement continues on the next line.

sloonz··on A brief look at async-await

  check()
    .then(result => {
      if (result) {
         // set state to finished
      }
      check()
        .then(result => {
          if (result) {
              // set state to finished
          }
          check()
            .then(result => {
              if (result) {
                 // set state to finished
              }
              check()
                .then(result => {
                  if (result) {
                    // set state to finished
                  }
                  check()
                    .then(result => {
                      if (result) {
                         // set state to finished
                      }

                      // set state to not done
                    })
                    .catch(error =>  // set state to failed);
                })
                .catch(error =>  // set state to failed);
            })
            .catch(error =>  // set state to failed);
        })
        .catch(error =>  // set state to failed);
    })
    .catch(error =>  // set state to failed);

For the love of everything that’s sacred, please don’t do this. The strength of promises is that they can free us from that exact kind of callback hell, and they do that by being chainable.

  const resultOrNull = await Promise.resolve(null).
       then(result => result || check()).
       then(result => result || check()).
       then(result => result || check()).
       then(result => result || check()).
       then(result => result || check()).
       catch(error => null);
Calling .then/.catch inside of a .then/.catch is a huge red flag. Almost always, you want to return the promise and chain instead.
sloonz··on Ask HN: When do you use a library vs. implement something yourself?
> 3. People star it

> 4. It has traction ie >10k downloads preferably >50k

Why ? Your home-made code probably don't check those boxes.