844
u/lor_louis Feb 28 '21
20
6
3
1
200
Feb 28 '21
[removed] — view removed comment
77
u/Papriker Feb 28 '21 edited Feb 28 '21
On it!
Edit: I came to the conclusion that I‘m bad at making music and will rather keep on doing bad programming
5
442
u/LaLiLuLeLo_0 Feb 28 '21
This looks like a lonely bit of code, floating in an empty orbit in space, millions of miles from anything else
944
u/Reeceeboii_ Feb 28 '21
. ✦ ˚ *
. . ✦
,
. . ゚ . ☀️client waiting
, .
. . .
✦
, 🚀 else{ res.sendStatus(409) } ,
.
. ˚
, .
. . *
✦
. . .
. 🌑 . .
˚ ゚ . .
🌎 caller , *
. . ✦
˚ *
. .
112
Feb 28 '21
This is beautiful, thank you.
37
4
14
26
5
3
1
265
u/Mc_UsernameTaken [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Feb 27 '21
When I find a callback hell like that everynow and then, I'll take some time to grep it all out and see what all the curly braces looks like.
184
55
41
33
24
u/Ramaness Feb 28 '21
Ohh this looks like a piece of art
5
u/passwordisoptional Feb 28 '21
Seriously. If someone makes a full size version, I'd use it as a phone background.
104
u/PhatOofxD Feb 27 '21
That's why you async await...
89
u/BakuhatsuK Feb 28 '21
That doesn't even look like callback hell. In callback hell you have a lot of
})instead of bare}.This looks like it needs some early returns and extracting some code to their own functions.
23
u/NiQ_ Feb 28 '21
Oh god you’re right... and they’re obviously not using a linter as the top line has }), with other nested lines having them separated.
15
12
1
22
12
11
u/revrenlove Feb 28 '21
Yo dawg, I heard you like closures, so we put a closure in your closure in your closure in your...
1
7
7
u/Blexit2020 Feb 28 '21
I just want to know what the "if" was. Seeing them separated like that is just heartbreaking. They should try to work on their issues and get back together.
42
u/rogue_potato420 Feb 27 '21
Javascript do be like that sometimes
26
u/rift95 Feb 28 '21
If you write it poorly.
There's also nothing really stopping you from writing the same mess in many other language.
5
5
5
16
4
4
4
u/DoobyMcFoosen Feb 28 '21
I've been working in CS for 7 years, and there's something I still don't understand about it.
[]— brackets{}— braces<>— diamond or wickets
If we already have unique names for these grouping symbols, then why do we call (2) 'curly brackets'? What is it about the word 'brace' that's confusing?
9
u/TheOldTubaroo Feb 28 '21
They can all be called brackets as well:
() round brackets, or just brackets in some places
[] square brackets
{} curly brackets
<> / ⟨⟩ angle brackets
Personally I prefer the version with unique names, though I still call <> "angle brackets" (or occasionally "chevrons", but that usually means «»).
2
u/Nafferty Feb 28 '21
I've met people who honestly only ever heard "curly bracket", so I stick with using it to avoid confusion for them. It might be clunkier, but sometimes you don't know who the audience is going to be. Might as well not get someone who might be listening hung up on that small detail.
4
u/bilbopoop Feb 28 '21
"Refactor this method to reduce the Cognitive Complexity from 148 to the 15 allowed."
1
u/apetc Feb 28 '21
Is it weird to sometimes comment these or unindents (in Python) when there's a lot in row so I know what block is ending?
1
2
1
1
3
u/FxHVivious Feb 28 '21
Just... Why?
0
Feb 28 '21
[deleted]
4
u/FxHVivious Feb 28 '21
To be honest, I'm just about to start my first job in industry, so I'm not super experienced outside of school, and I've never seen a string of brackets like this before.
3
2
2
2
2
2
2
u/Irtexx Feb 28 '21
Can somebody please recommend a design pattern to replace deeply nested if statements (what this pic likely is) I.e. For when you have multiple preconditions you want to check before doing something. I've tried using an "And" instead of nested ifs, but then you cannot match each if with its own else, which is useful if you want to log or print to the console the reason why the precondition failed.
2
u/ssjskipp Feb 28 '21
Couple ways, easiest is mentioned below (exit on failure and continue on not -- this is the same as making assertions instead of conditions).
Another way is similar and utilizes the idea of a
Either[L, R]monad where one side is an error and the other is the value. The idea being you have assess to choose which side tomapon, and can chain logic.In JS, promises act like this (failed promises fall through to a 'catch' or a consuming 'reject'). In F# there's this bit on "railway style" https://fsharpforfunandprofit.com/posts/recipe-part2/
1
u/No_Animator_8599 Dec 15 '22
I would just break it down by calling a new method so it becomes easier to manage. I worked in multiple languages and found if/else statements with too many conditions a nightmare to work with.
0
2
2
2
2
2
2
2
u/tintin10q Mar 29 '23
The 409 makes it so much more cursed as well. Like when your sending 409 you are much deeper than is probably fun.
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
u/Jumpy-Economist Mar 22 '22
How do you avoid a huge chain like this? I've often had larger programs where the bottom can look like this
1
1
1
0
Feb 28 '21
[deleted]
3
Feb 28 '21
No guard keyword in js sadly
9
u/manghoti Feb 28 '21
I'm not familiar with the guard keyword. But guard constructs work ok in JavaScript, just invert your ifs and then early escape.
2
0
Feb 28 '21
[deleted]
3
Feb 28 '21
Gotcha. I'd never heard the term guard clause even though it's something I regularly do in my code. In swift there is an explicit guard keyword that allows for optional binding and forces you to exit the function if your guard condition fails.
9
u/TheOneWhoWil Feb 28 '21
Is this a real rest api?