4 ms·
"clever compilers can reuse addresses of variables for as long as they are not written to" Still chewing on this, but it would immediately strike me that relyi
by laythea 9y ago
"clever compilers can reuse addresses of variables for as long as they are not written to"
Still chewing on this, but it would immediately strike me that relying on this behaviour in a software application, for it to be performant, would be a bad idea.
- manmal 9y agoSince the type system is so strict, the compiler can often infer immutability even for mutable variables, and avoid copying in those cases. Swift’s compiler will even warn you if you declared a variable mutable when it’s never mutated. It’s an optimization rather than a guiding principle, but a very powerful one. Swift now is quasi on par with C++ performance, also thanks to optimizations like this.
- laythea 9y agoThanks for the info, that's interesting (I didn't know that). But it still seems like cheating :)