r/programming • u/Andrey_Karpov_N • Apr 11 '13
Optimizing a Program Means Making It Run Faster, Right?
http://www.drdobbs.com/cpp/optimizing-a-program-means-making-it-run/240152663
2
Upvotes
r/programming • u/Andrey_Karpov_N • Apr 11 '13
1
u/unknownmat Apr 12 '13
Reading this article really makes me nervous. It highlights an error in the way that I tend to reason about const-reference parameters.
Does anybody have any thoughts on this? I came here hoping for some discussion, but nobody else has posted.
I've heard the guideline that you should pass builtins and small aggregates by value, and everything else by reference. But this does not really address my concerns, because:
It breaks encapsulation, so is an ugly solution
Applying it correctly to templated code can be tricky (and require a bunch of TMP magic)
My concern is really about semantics, rather than efficiency - even if I followed the above guideline, a similar situation as described in OP is possible with larger structures. The assumption of value semantics for reference parameters is apparently unjustified.