this post was submitted on 26 Aug 2026
366 points (100.0% liked)

Programmer Humor

32965 readers
1801 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 3 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] chad@sh.itjust.works 4 points 3 hours ago* (last edited 3 hours ago) (1 children)

Please avoid nested if statements. Instead use early returns when possible.

See video explanation.

[โ€“] chicken@lemmy.dbzer0.com 1 points 1 hour ago* (last edited 1 hour ago)

Early returns seems good, but personally I find code more confusing when things get arbitrarily separated out into functions, because to read it you have to keep scrolling back and forth between different parts of the page and either remembering where the other part is or typing a lot with ctrl-f, there's more variables to hold results, and if the section of code to be separated into a function is picked just because of nesting depth reasons then it's likely the function name isn't going to describe what it does very clearly, leading to more scrolling and more having to keep track of things in your head.