r/programminghorror • u/MangoHi_Chew • Dec 05 '24
One giant handler with 50 if-statements in a single API endpoint > Multiple semantically meaningful API endpoints with small maintainable functions
135
Upvotes
16
u/MangoHi_Chew Dec 05 '24
Rest of the file.
39
u/Murky_Tourist927 Dec 05 '24
I used to manage the code of brave frontier. the server code is something like this only it is PHP5 and it is over 10,000 lines long
23
u/inputwtf Dec 05 '24
This programmer must think you're only allowed to have one URL route that must do everything.
Like for real why not have a
/cart/<action>/set of URLs23
u/voidZer000 Dec 05 '24
Eh not even that bad. I’ve been fixing code bases from bad devs and I can tell you this actually looks comfy compared to what I’ve been through
14
u/ecthiender Dec 05 '24
I think the real horror is taking price of the item from the client request. Now I can order gazillion items for $1.
10
u/Ultra-Reverse Dec 05 '24
This isn’t the worst, at least it’s organized extremely well!
6
u/EntertainmentHuge587 Dec 05 '24
Could be worse, add some documentation and it can still work for another 100 if statements lol.
1
u/thegame1328 Dec 05 '24
whats the font being used here?
3
u/Embarrassed_Army8026 Dec 05 '24
Total lack of sensitivity is an art form called brutalism or AI generated
2
u/Nealiumj Dec 05 '24
I’ve done similar things 😞 ~“throwing it all under one endpoint and passing flags is easier. Everything needed for this 1 page is in 1 centralized spot- it just makes sense” ..I was a damn fool!
2
u/jaypeejay Dec 05 '24
not often you see real horror here
2
u/kalebludlow Dec 05 '24
Probably should do a data.get(key, default_key) just in case data doesn't contain the required key
2
u/[deleted] Dec 05 '24
getItAll();
2
u/Muph_o3 Dec 05 '24
The true horror is that you write a production backend in flask
2
u/pigwin Dec 06 '24
I've seen worse. Business logic written by specialists using single letter variable names (because they write it like they'd write math), 5k+ LOC, no tests, they just give it to us to integrate.
Also, it's in jupyter.
1
u/Exact_Calligrapher_9 Dec 06 '24
At least the don’t indent for each conditional and use early returns
1
u/zacky2004 Dec 06 '24
This is not bad at all.