this post was submitted on 24 Sep 2023
215 points (93.2% liked)

Programmer Humor

40930 readers
81 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] emerald@lemmy.place 57 points 2 years ago (3 children)

If your code is that deeply nested, surely something has gone horribly wrong, yes?

[–] yogthos@lemmy.ml 14 points 2 years ago (1 children)

Problem is that Js kind of encourages this being single threaded and using callbacks for anything blocking. To be fair, the new async syntax sugar helps in modern Js, but nesting a bunch of callbacks or promises was basically the way you did stuff for the longest time.

[–] h_a_r_u_k_i@programming.dev 9 points 2 years ago

Code aesthetic: If your code looks like a triangle, you're seriously doing something wrong.

[–] Blackmist@feddit.uk 5 points 2 years ago (1 children)

I prefer a bunch of

if (fucked_up) {return(error_code);}

for checking common errors.

[–] DWin@sh.itjust.works 2 points 2 years ago

Yup, never nest.

All the conditions should be checked and returned if they failed as you go through the function with the successful response being the last line.