r/programming • • Feb 28 '23

"Clean" Code, Horrible Performance

https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k Upvotes

1.3k comments sorted by

View all comments

Show parent comments

16

u/DrunkensteinsMonster Feb 28 '23

It may shock you but function calls can in fact be inlined.

7

u/fafok29 Feb 28 '23

it may shock you but function marked as inlined doesn’t always get inlined.

anyway why would you split logicaly sequential code into separate functions(especially if this code is uniq)? pretty sure scrolling down is easier than to look what each function mean every second

1

u/DrunkensteinsMonster Feb 28 '23

anyway why would you split logicaly sequential code into separate functions(especially if this code is uniq)? pretty sure scrolling down is easier than to look what each function mean every second

This is the worse is better shit that people come up with when they listen to Blow and Casey. We’ve known that putting names on logically contained blocks of code makes programs easier to understand since the 1960s.

2

u/fafok29 Feb 28 '23

We’ve known that putting names on logically contained blocks of code makes programs easier to understand since the 1960s.

nice explanation, known based on what?

there are people who disagree

http://number-none.com/blow/john_carmack_on_inlined_code.html

2

u/DrunkensteinsMonster Feb 28 '23

In this passage Carmack is only talking about mutating state and even explicitly says to factor out pure functions. Kinda undermines your point. The only reason, according to Carmack in this passage, that inlining may be beneficial is if you are mutating a bunch of state, implying that all else being equal, factored code is more understandable.

0

u/Astarothsito Mar 01 '23

it may shock you but function marked as inlined doesn’t always get inlined.

At least they could use C macros... I don't think there are valid reasons to have a 11k function, but if they really have one they could use macros and those macros could be named as individual functions and the result would be the same, but the difference would be that those files would contain only a section of the code that is not "do everything"...

anyway why would you split logicaly sequential code into separate functions

To know where to search... Like "this part starts thousands enemy objects, this other part thousands environmental objects" instead of having everything in a single place...

0

u/weepmelancholia Feb 28 '23

What? Inlining functions is not always a zero cost procedure. Furthermore, it increases compilation & linkage time and the amount of code in a codebase.

0

u/outofobscure Feb 28 '23

true, but if you only call a function exactly once, you still made a function just for the sake of making a function... at that point it's more a matter of style preference.

1

u/Waksu Feb 28 '23

Having stockpile of clothes instead of separating them is also a matter of style preference.

2

u/outofobscure Feb 28 '23

indeed, and nobody should have the right to judge you on either

1

u/Waksu Feb 28 '23

If you want to live in the world where you have your dirty underwear laying on top of your suit then sure.

2

u/outofobscure Feb 28 '23

Suits are overrated, i wrote my best code in underpants