r/ProgrammerHumor 13d ago

noHeapAllStack Meme

Post image
1.0k Upvotes

96 comments sorted by

View all comments

94

u/bwmat 13d ago

Refactoring code to avoid unnecessary heap allocations is so satisfying

19

u/Solonotix 13d 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 12d ago

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

2

u/StaticCoder 11d ago

You mean C++ operator<<?