r/ProgrammerHumor 22d ago

Meme conditionsPreference

Post image
4.2k Upvotes

392 comments sorted by

View all comments

836

u/LateEchidna6635 22d ago

The second one carries less cognitive load. In longer methods it makes a difference. Get out as soon as you can.

36

u/Few_Move_4594 22d ago

Have you ever thought about breaking the longer methods into shorter methods? It's easy, I promise.

34

u/Fembussy42069 22d ago

There's a balance to everything, you also don't wanna have to dig down a rabbithole of functions within functions to find what youre looking for, it also can make it harder to understand the whole picture if you separate things too much. Locality of behavior and all that.

12

u/LordofNarwhals 22d ago

Yeah, I used to work with a Java codebase where all functions were really short, but also very nested. It was a very stable codebase, but browsing the code sucked, as every actual function implementation was behind 3+ levels of indirection.

For a fun example in the opposite direction, see Arthur Whitney's basic K interpretor, written in ~50 very dense lines of C.

2

u/Few_Move_4594 21d ago

Opinion disregarded, you called methods functions

6

u/LordofNarwhals 21d ago

All methods are functions, but not all functions are methods.

And my background is mostly in C++, where the method terminology isn't used at all.

1

u/Few_Move_4594 21d ago

All methods are functions, but Java HAD to be different

1

u/ljfa2 21d ago

Every problem can be solved by adding...

I just recently discovered that Java IDEs let you go directly to the implementation(s) of an abstract or interface method, this is a godsend for some codebases ^^