Is Rust syntax really that different? I've only written a little C++, but it seems pretty similar to me. They mostly just switched from `type x = ...` to `let x: type = ...` and let you return stuff by putting an expression at the end of a block, right?
Right, but while that's a bunch of stuff the syntax here isn't intimidating.
It's a mutable reference to an Arc of a Mutex of an Option of a Box of MyStruct.
You presumably could build yourself one of these in C++ although since the standard mutex in C++ can't actually protect anything (you're supposed to just remember to lock it anywhere you need to, you know, because C++ is a language for people who never make mistakes) you would need to build that part yourself.
And if you did build that yourself in C++ the syntax for the type would look rather similar, although I guess C++ allows you to just say auto meaning, "I dunno, guess" for the return type in a function signature whereas Rust insists you must actually write return types and don't leave them for the compiler to figure out.
Rust deliberately chooses not to infer the return type in a function signature.
Inferring return types is convenient for the person writing the function, but adds cognitive overhead for people using the function and makes it easier to introduce incompatible changes without realising (the signature you wrote is unchanged but a different signature is now inferred)
Not arguing that. Indeed forcing type signatures helps the reader at the expense of the writer (who has the burden of documentation? S/He who writes the types).
I’m saying, to a person with less skills than I, it’s an almost insurmountable undertaking to learn Rust while Go at least seems somewhat familiar. They aren’t teaching these in universities I visit so new engineers might have a tough time grokking the syntax.
I prefer Go for two reasons. 1) It’s faster for me to get my idea across (this is my personal hurtle) and 2) Go’s concurrency model.
What I would like to try in Rust: rewriting my game engine. Building a hobby OS. Building a hobby programming language. These are areas where Go isn’t the best tool.
The return type might be inferred, but you're definitely supposed to remember locks. Nothing in the language will prevent you from accessing a protected resource without locking the lock.
Making a locking thread safe slice or map is as easy at creating a struct with two fields and three member functions… then you can access it and it will lock itself and unlock itself.
From Rust point of view, if you have to write these signatures, something may be off with your architecture. I.e. this is a thing that needs to be mutated from multiple threads, abstracted by a virtual table, and be nullable. And for some reason, this is an exclusive borrow to such pointer. It’s likely that removing any of these constraints would make a positive impact on the architecture.