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

Programmer Humor

32965 readers
1067 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
[–] chicken@lemmy.dbzer0.com 4 points 6 hours ago* (last edited 6 hours ago) (1 children)

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.

[–] PabloSexcrowbar@piefed.social 3 points 4 hours ago (1 children)

A good IDE makes it unnecessary to scroll back and forth like that, though.

[–] chicken@lemmy.dbzer0.com 3 points 3 hours ago* (last edited 3 hours ago) (1 children)

How? I'm using vscodium. There are right click menus that bring you to function definitions and uses, but that isn't necessarily faster than scrolling around and is still way more friction and more stuff you can't see to hold in your short term memory.

IDEs also have collapse/expand features which make nested or longer functions easier to navigate.

[–] wols@lemmy.zip 2 points 1 hour ago (1 children)

In a decent IDE you can CTRL+click (or similar) on a function name to go to its definition. This is absolutely faster than scrolling, especially if you've got more than a couple dozen lines in the current file.

When splitting functionality into smaller functions you would ideally not have to keep implementation details of other functions in short term memory.
You only need to understand/remember the contents of the current function. Does it do what the name suggests? Cool, you're done checking it.

Of course, the "2 hard problems in computer science" meme exists for a reason - it's not always straight forward to come up with good names. But in my experience, even when coming up with a fitting name is difficult, reducing nesting usually helps a lot with comprehension, mainly because it reduces scope and thereby the amount of information you need to hold in your head.
The larger a function gets, the harder it is to check that it does what it's supposed to.

There is of course a balance to strike - trying to force every single function to be at most 3 lines is likely to make the code more difficult to understand and is, in my eyes, almost pathological. But a function that covers more than a screen is the other extreme that should be avoided when practical.

[–] chicken@lemmy.dbzer0.com 1 points 1 hour ago

CTRL+click

Oh hey it works, thanks.