456
got him (lemy.lol)
submitted 3 months ago by ngn@lemy.lol to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] Kimano@lemmy.world 20 points 3 months ago

My personal code readability axe to grind is nested complex ternary operators.

Every now and then I'll see something like this

return (checkFormatType(currentObject.type==TYPES.static||currentObject type==TYPES.dynamic?TYPES.mutable:TYPES.immutable)?create format("MUTABLE"):getFormat(currentObject));

And I have a fucking conniption because just move that shit into a variable before the return. I get it when sometimes you just need to resolve something inline, but a huge amount of the time that ternary can be extracted to a variable before the ternary, or just rewrite the function to take multiple types and resolve it in the function.

[-] lud@lemm.ee 8 points 3 months ago

That example looks like the PowerShell equivalent of piping complex things around 20 times before actually doing something with the results.

[-] Skullgrid@lemmy.world 8 points 3 months ago

no but bro, the code complexity tool says that this scope has 14 complexity instead of 13, we gotta cram it in a single ternary for code legibility

[-] dejected_warp_core@lemmy.world 7 points 3 months ago* (last edited 3 months ago)

In a one-liner competition, sure.

In my codebase? I'd pull a "let's linger after standup about your PR" and have the coder sweat through a 10 minute soapbox about nothing before laying down the law.

[-] Kimano@lemmy.world 3 points 3 months ago

Yeah, the annoying thing is the people who I generally have found to be the worst about stuff like this are old school Senior C developers, who still program like it's 1987 and we have to fit everything into 4K of RAM.

Fortunately there's nothing like that in my code base, I just run into stuff like that periodically when I'm digging around in other team's server code looking for something.

this post was submitted on 09 May 2024
456 points (92.4% liked)

Programmer Humor

31717 readers
919 users here now

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

Rules:

founded 5 years ago
MODERATORS