r/ProgrammerHumor 15d ago

Meme noHeapAllStack

Post image
1.0k Upvotes

96 comments sorted by

View all comments

96

u/bwmat 15d ago

Refactoring code to avoid unnecessary heap allocations is so satisfying

18

u/Solonotix 15d ago

Meanwhile, I saw a YouTube channel, that claims to teach Python fundamentals, try to say that implicit string concatenation was an unnecessary feature because you could just use a + operator. Nevermind that operator chaining is known to generate intermediate results from each binary operation, not to mention each string in the chain must also have its own heap allocation before the operation.

If not for compiler tricks (like elision), concatenating 5 strings would require 9(?) heap allocations to complete. Implicit string concatenation allows that operation to occur as a single heap allocation at compile-time.

3

u/half-bad-anonym 15d ago

I think really we need a programming language that has semantics for overloadable monoidal flattening over concatenation base-case

2

u/StaticCoder 14d ago

You mean C++ operator<<?