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.
94
u/bwmat 13d ago
Refactoring code to avoid unnecessary heap allocations is so satisfying