Hey! This is my first ever DEV post. Tell me if you liked it and if you'd like to read more stuff like this! 😄
So, Rust. It's a language that has ...
For further actions, you may consider blocking this person and/or reporting abuse
Other differences can be:
template, Rust do not have that.Lots of Rust dev still depend on NodeJS to do Frontend stuff (I know Rust can do WASM),
but still for some reason, a lot of people still depend on NodeJS and TypeScript,
if thats a Pro or Con, is opinionated, but I prefer to not fight with
node_modules, etc.More idiomatic Nim can be:
Mainly the return type, I would add
{.inline.}if was my code :PGood comparison, nice post, I think you have more experience with Rust, both awesome languages.
Hey! Thanks for replying.
I do agree, the other differences you pointed out are key. I actually mentioned the identifier with backticks trick as stropping, turns out that's what it's officially called.
About the
funcvsproc—I don't know how I could forget about that. I'll actually edit the post for this.I actually do not have more experience with Rust; I know both of them moderately well, but know a lot of stuff about them.
Really, thanks for replying, it means a lot!
Some notes:
First, you don't need the turbofish in your Rust. Rust's type inference is really powerful, and in the following code:
It still can understand that
numberis an integer (due to it being used in the range).Second, Rust can compile to JS, too 😃. This is thanks to LLVM - any language compiled to LLVM IR can be converted to asm.js or WebAssembly.
Second, the
?operator is not a shorthand for.expect()nor.unwrap(); it's desugared like this:Third. The typing "boilerplate" the Rust code has compared to Nim in the example is just due to the ability to omit
main()in Nim. Of course, in real-world program there isn't a difference.Fourth. Rust has really powerful macro system, too. You've chosen to use a library that doesn't use that, and that's OK. There are people that prefers this style (I too, in most cases). But even if there aren't libraries that allows you to write code like your Nim server, this is clearly possible.
Fifth. I don't know Nim much, but AFAIK it has exceptions. Rust could have exceptions, too (in fact, you can simulate them), but there is a reason it chose not to do so. Exceptions are really, really bad in production. Decades of engineering proved that. They're really "you can't without them, but you also can't with them".
Sixth. Not having GC is really an advantage for Rust. Reference counting bring Nim closer to Rust (it also has some form of it), and can be better for system programming (because of the GC's latency), but still adds overhead. For each store. Rust, not only it can eliminate the need in most of the cases due to compiler's excessive knowledge about the program, also idiomatic Rust almost doesn't get to this situation because of the ownership and borrows.
Seventh. The biggest advantage of Rust is its safety. Rust wasn't created to answer the need for a modern system programming language (although it answers it too), but to answer the need of a safe system, concurrent programming languages. Again, I don't know Nim, but from what I've read about it, it doesn't deal with this problem at all.
Eighth. Rust isn't Python, and it's not good for small programs. The advantages of an intransigent compiler become obvious as your project grows. Ask the folks at Microsoft about the need in TypeScript and the ever growing ecosystem around it - static typing over a dynamically typed language!
Ninth. Syntax is really matter of preference, and one can claim that C's syntax is the worst invented. But anyway, the people that program in Rust are not students; they're people working at REALLY big projects. Those already have experience with C-like languages. The fact that almost all (if not all) mainstream languages use C-like syntax is not accidental.
Tenth and last, but certainly not least. Rust is more mature. With a big difference. The users are more, the packages are more, and the ecosystem is enough to build real programs. The fact that several big companies use Rust in their big projects at least not disturb that. Nim ecosystem, although older, is not there. It can get there, eventually, but if you ask for my guess - it won't. There isn't enough space for many system languages, and this area in the industry is changing very slowly. Nim could be a great language to replace, say, Java and C#, but it doesn't aim there. And I think there is a room for one, and only one, language to replace C/C++.
The factorial nim program can be rewritten as (without the result var and return proc):
True!
Just want to add: Nim now has automatic reference counting (à la objective C) as a memory management option--soon to be the default. So no garbage collector needed any more!
I didn't know that, that's sick! Can't wait! 🎉