Go kinda ruined other languages for me with multiple return values, its something I miss when working in every other language now. And reading through the docs I keep hoping I would stumble across that, though that would create a lot of problems when interfacing with C. Type inference is a huge win, standard libraries looks solid, love the potential around marking variables as mutable, and any language that has no null values makes me happy.
Overall, I wish I had more time too.
Also, I've never come across a situation with too few/extra semicolons causing any kind of logic errors. The compiler will complain at you if you get it wrong.
Also, the type checker ensures that you'll hear about it if you lack a semicolon and emit a value other than unit from a block, without then using it.
fn addsub(a: int, b: int) -> (int, int) {
(a + b, a - b)
}
...
let (a, b) = addsub(32, 44); let a = 1;
let b = 9;
let (b, a) = (a, b);
printf!("a: %i, b: %i", a, b); // a: 9, b: 1
...or say you just wanted to grab a single item out of a tuple: let x = (1, 2);
let (_, y) = x; // the underscore is the pattern for "ignore this"
printf!("y: %i", y); // y: 2 b, a = a, b
is actually valid code in Lua (and works as expected).Grabbing only one value looks like this
_, y = returnsTwoValues() -- grab only the second
y = returnsTwoValues() -- grab only the first a,_ = two_values()
_,b = two_values()The large amount and rapidity of change makes it difficult to use it seriously. It's nowhere near as stable as other newer languages like Go and Scala are, for instance.
Some experimental programs I wrote a mere 8 months ago are now basically unusable with recent versions of Rust due to language, syntax and standard library changes.
Unless you can constantly track Rust's development on a daily basis, and update your code accordingly, I'd be very hesitant to suggest using it for anything but throw-away code at this point.
It reminds me of Go a couple of years ago, but that had "go fix" which would mostly update your source files to the newest revisions. That made early adoption a lot nicer. I'd love to see a "rust fix"
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.
> 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.It will, because the semicolon in Rust actually has a semantics impact: `a` has type T(a) but `a;` has type Unit (~void).
> Go kinda ruined other languages for me with multiple return values
That's sad, because Go has one of the worst MRV implementations out there: it's a special case of the language itself.
In most languages with MRV — and that includes Rust, but also MLs, Haskell, Erlang, Python or Ruby — MRV is simply a natural consequence of being able to unpack or pattern match containers (tuples and/or lists depending on the typing discipline).
Anyway Rust has multiple return values, don't worry about that.