Yes, I agree that I have the same intuition. I’m just not satisfied that I fully understand why I have this intuition, and where the dividing line lies precisely.
When I made the nim bindings, I had to write some code to make this decision (whether a type was a “by-reference” or “by-value” type) automatically, and I could never find some satisfying criteria for deciding this, I ended up special-casing lots of things. Maybe we need some way of tagging these types in the source code, so that the binding generator can do the right thing.
In any case, for vector types it’s obvious, and I will be making sure these methods return a copy instead of a reference.
For what it’s worth, when you get a WindowProperties object from a window, you are getting just a snapshot of its current values; this class is intended to be used by-value in C++.
Yes, this is fair, there is a slight extra price we pay for the extra heap memory allocation. I am not sure how much extra time this will take on top of allocating the Python wrapper object, I’ll have to time it.
I have considered a potential optimization to the bindings, by allocating the storage for the vector as part of the storage for the Python wrapper object, which would not only eliminate the extra allocation, but also reduce the overhead of using vector types in general. This would only work for types that are considered “by-value”, like vector. However, this requires significant changes to the binding generator, so I’m not sure if and when I’ll get around to it.