12-15-2021, 08:29 PM
(12-15-2021, 03:17 AM)beta-user Wrote:(12-14-2021, 10:40 PM)ryo Wrote: So I end up wrapping everything I make in Node into "promise.then.then.then.then..."
Just use async / await to avoid nesting callbacks .
(12-14-2021, 10:40 PM)ryo Wrote: If I don't wrap everything into promises, thought process always goes like "WTF, I just solved this one bug only to create 5 new bugs!?" (refresh) "Oh, it got fixed by itself." (refresh) "NOW THERE ARE 20 NEW BUGS!?".
That doesn't sound right. Only a few things are asynchronous in Node.js like network requests and file operations (but those can be done synchronously too), because like you said async isn't always needed in programming. Asynchronous methods return promises and only with those you have to use .then or await if you want to do something after they complete.
It would still be nicer if we'd have to explicitely state it's an asynchromous code in a synchromous language rather than the other way around.
But that's perhaps the kind of debate of whether we should put ice in a glass and pour soft drinks over it, or put soft drinks in a glass and then drop ice into it.
If you're a newcomer to programming, then either way wouldn't really be a problem, since you're starting from scratch.
But if you've already been programming for over a decade exclusively in ANSI C, C++, Shell Scripting, and PHP (which is me by the way), the whole concept of promises is truely a mindrape.
母語は日本語ですが、英語も喋れます(ry