Live data from Hacker News

Callback Hell (2016)

callbackhell.com

81–90 of 170 posts

Re: Callback Hell (2016)

#81
post #73
post #69

Earlier quoted context omitted.

It's because when you use 4 spaces, the lines just become too long. I use 4 spaces in C and 2 in javascript and that makes sense visually for me.

If your lines are too long with 4 spaces, then you either have a tiny screen, or aren't line-breaking when you should be. Or you're in callback hell...

yeah tiny screen, does that make me a bad programmer?

Re: Callback Hell (2016)

#82
post #72
post #69

Earlier quoted context omitted.

It's because when you use 4 spaces, the lines just become too long. I use 4 spaces in C and 2 in javascript and that makes sense visually for me.

Let me guess... It is hard for you to read long lines or your monitor isn't big enough? You might call that an accessibility thing right? You get what I'm getting at. You traded one accessibility that is fairly easy to fix (at worse case you have line wrapping) for one that is almost impossible to fix (zooming and large font don't really help).

It's hard for me to read long lines.

I don't think 4 spaces makes it easier to know in what scope I'm in when there are a lot of scopes. The amount of white space is a bit overwhelming to me.

But you know, it's no big deal, just a matter of taste. Maybe 3 spaces is a better answer, which I guess we'll never know...

Re: Callback Hell (2016)

#83
>Personally I use callbacks for 90% of the async code

I stopped reading right there (well, it's near the end of the article anyway, and I did continue, but you get my point).

Re: Callback Hell (2016)

#84
post #81
post #73

Earlier quoted context omitted.

If your lines are too long with 4 spaces, then you either have a tiny screen, or aren't line-breaking when you should be. Or you're in callback hell...

yeah tiny screen, does that make me a bad programmer?

Well, better programmers can afford larger screens :-)

Re: Callback Hell (2016)

#85

Serious question: what is considered async? From the site, I get that add(1+1) doesn't require a callback, whereas downloadFile(url) does. What about somethingHarderThanAddition(noExternalDependency)? My question is, what is the threshold that I can assume that my code will run sync, and when it cant?

>My question is, what is the threshold that I can assume that my code will run sync, and when it cant?

It will always run sync, unless you call something that accepts a callback (either at the first level, or nested in something else you call).

Re: Callback Hell (2016)

#86

Serious question: what is considered async? From the site, I get that add(1+1) doesn't require a callback, whereas downloadFile(url) does. What about somethingHarderThanAddition(noExternalDependency)? My question is, what is the threshold that I can assume that my code will run sync, and when it cant?

> what is the threshold that I can assume that my code will run sync, and when it cant?

Generally you won't have a choice. If something in your function calls another async function, the function as a whole is forced to be async. If not, then it won't be.

It's possible to make a function fake-async even if it doesn't call any async functions, by just calling the callback at the end. But there's not much point -- and callers may make assumptions about the the callback being called in a separate iteration of the event loop, so doing that could cause subtle bugs. That latter problem is solvable by calling the callback in a setImmediate callback, but again, no point unless you have a good reason to.

(Exception: there are a few apis where you do have a choice, e.g node's randomBytes can be either sync or async. Generally they're things that might block, where the sync version returns an error if it can't satisfy immediately. But generally you don't.)

Re: Callback Hell (2016)

#87
post #62
post #52

Earlier quoted context omitted.

Actually `setTimeout` is not part of the core language, it's a Web API.

I think the point they were trying to make is that all JS is almost always used with a run loop. Whereas Ruby and Python are often used without a run loop.

> I think the point they were trying to make is that all JS is almost always used with a run loop.

Sure, but criticising a rant about the propogation of misconceptions by propogating a misconception seems like a self-undermining position :)

Re: Callback Hell (2016)

#88
post #82
post #72

Earlier quoted context omitted.

Let me guess... It is hard for you to read long lines or your monitor isn't big enough? You might call that an accessibility thing right? You get what I'm getting at. You traded one accessibility that is fairly easy to fix (at worse case you have line wrapping) for one that is almost impossible to fix (zooming and large font don't really help).

It's hard for me to read long lines. I don't think 4 spaces makes it easier to know in what scope I'm in when there are a lot of scopes. The amount of white space is a bit overwhelming to me. But you know, it's no big deal, just a matter of taste. Maybe 3 spaces is a better answer, which I guess we'll never know...

How long of a line are we talking here? Most coding standards are 80-120 with maybe some at 140.

If you are say 4 levels deep the additional characters used over 2 spaces is 8 characters. You got whopping 8 additional characters to make an even longer line of code (code to be interpreted or read) and screwed over the people who need the indenting.

If long lines are a problem than just refactor. I agree long lines are hard to read but there is a simple fix. Either refactor or just put in a line feed (or however the PL deal with long lines aka \ for bash or python).

Re: Callback Hell (2016)

#89

Serious question: what is considered async? From the site, I get that add(1+1) doesn't require a callback, whereas downloadFile(url) does. What about somethingHarderThanAddition(noExternalDependency)? My question is, what is the threshold that I can assume that my code will run sync, and when it cant?

Anything that suspends processing and waits for the OS to provide some data (file, time, socket, or piping usually) should be behind a callback. Beyond that benefit is more limited (in a single threaded app like NodeJS), since you are no longer using async to do othe stuff while you wait for resources. However, if the computation locks up the thread for too long, it cannot service callbacks, and so timers might be delayed, heartbeat messages might be skipped leading to dropped connections, and other bad stuff. If that's the case you want to either split your large computation into many smaller ones (allowing other callbacks to fire in between) or offload the computation into another process or thread.

In other words, it's an engineering decision, based on the expected consequences of the overall design in the context of understanding how the event reactor works.

Re: Callback Hell (2016)

#90
post #69
post #63

I don't consider myself a huge code style pusher but when I see two space indentation I have to really ask... seriously... why???!!! Its funny to me because the languages where you get massive nesting you almost want greater indentation as it gets extremely confusing as to what scope you are in. While I prefer either 4 spaces or tabs (obviously not mixed) I'm not completely revolted with 2 spaces in Algo languages li…

It's because when you use 4 spaces, the lines just become too long. I use 4 spaces in C and 2 in javascript and that makes sense visually for me.

Does your code look like the code in the example? With the useless else clauses? And without sensible extraction of standalone functions?
Post reply on HN