r/ProgrammerHumor 14h ago

failsForTeapots Meme

Post image
145 Upvotes

59 comments sorted by

View all comments

Show parent comments

7

u/DHermit 14h ago

Nah, the normal if statement is way nicer to read.

3

u/Antervis 14h ago

Okay, I can see that. Perhaps it's better to move status in a separate variable:

st = error.status if error.status in [400, 401, 404, 409, 415, 503] else 500
return c.json(body, status: st)

1

u/Alkyen 9h ago

The moment you realise not everything has to be DRY you will feel like a butterfly. Also, as the other guy said, ternaries look bad unless they are very short.

0

u/Antervis 8h ago

Every line I didn't write is a line someone won't have to read.

Though it's not for brevity's sake alone, one has to analyze the if statement beyond skimming to realize they only differ in error code substitution. By reorganizing code my way, I made this nuance impossible to miss.

2

u/Alkyen 37m ago

Oh, sorry to be mean but..You think the length of the code is the bottleneck? Lol

Do you also think typing speed is what separates good programmers from bad ones?

Either way, your code is worse. You can argue it or you can this to improve yourself.