3 ms·
Go is not the only language with multiple return values. Lua for example had them before Go. In Lua it would look like: addsub = function(a, b) return a + b,
by copx 13y ago
Go is not the only language with multiple return values. Lua for example had them before Go. In Lua it would look like:
addsub = function(a, b) return a + b, a - b end
a, b = addsub(32, 44)
And if you run that code with LuaJIT it compiles down to a few machine code instructions, no object creation at all, no function call.
In contrast I think at least in Python the tuple based solution would be horribly inefficient because it allocates/deallocates a new object every time just to pass values. I don't now if the Rust compiler is smart enough to optimize the tuple creation away.. but I doubt it.
- kibwen 13y ago> I don't now if the Rust compiler is smart enough to > optimize the tuple creation away I'm sure it can. LLVM is a really, really good backend.