3 ms·
Where? Variables are a language semantic not an implementation detail. A temporary variable is just a new symbolic name. You may be thinking of temporary stora
by brrrrrm 5y ago
Where? Variables are a language semantic not an implementation detail. A temporary variable is just a new symbolic name. You may be thinking of temporary storage
- robomartin 5y agoSemantics. You still have to use additional resources for the swap. BTW, in Python, "a,b = b,a" is actually faster (execution time) than explicitly using a third variable. In other words, I am not saying it is a bad technique, just saying it has to use additional resources for the swap, that's all. In fact, the Python idiom is faster even if you doing something like: a,b = b[:],a[:]
- nomel 5y ago> Semantics I would claim it's not semantics. Variables are meant for humans, not computers. Variable does not necessarily mean storage. If you're outside of interpreted languages, the code you type is very often not the code that is executed. If this were a compiled language, there's no way to know if temporary storage was used or not, without looking at the generated machine code. There's a very real chance that something as useless as swapping variables would be optimized away completely.