Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
If this is JS, it's super wrong. Do yourself a favor and learn promises, async, and await
-
@nam17887 I once did an analysis on a few thousand public GitHub repos, and 2 spaces indeed started to become popular in the early nodejs callback hell days. Repos which utilized promises, and later async libs and ES6 started switching back to 4 spaces.
-
leanrob36646yI’ve seen that language before, I think it’s R.O.T
(Refactor or Trash)
Fuck that code is ugly -
@Codex404 @NotFound @TheyCallMeMJ @fristys @leanrob
It's interacting with a database. Two calls to the database, each with it's own forEach loop to handle the results. And one call back at the end, which I will be refactoring. But yeah the DB stuff doesn't seem to offer awaiting afaik. I'll take a look for it. But there are some nested loops so it would still only half the hellish nature of it.
@nam17887 @bittersweet @nmaggioni @mszaf
I always think it's funny how much people swoon over vim as if it's God's perfect editor, but every time I share screenshots with the default vim tab size, they're like "ew ugly editor" so I keep it that way.
@Fabian
IDE has a background which is transparent, darkened, and blurred. -
@AlgoRythm HackerNoon has some good 101s on callbacks vs promises vs async/await:
https://hackernoon.com/should-i-use...
https://hackernoon.com/6-reasons-wh...
I'd pick a solution which uses modern ES6 syntax + babel (in case your interpreter doesn't support it). On a modern node version, you might not even need babel.
ES6 + babel "transpiling" is the method which will be easiest to maintain in the future. Custom libraries might have breaking changes or become unsupported, while ES6 features are pretty stable going forward. When interpreters change, you maybe just change a babel config flag and you're good to go again. -
@bittersweet I know what babel is, and I know how to work async and await. I chose to use a call back in this instance for socket.io, utilizing their response callback features. And mysqljs doesn't have awaitable functions, so I'll need to convert them using utils.promisify
Guess the language...
rant
c a l l b a c k s