Hacker News new | ask | show | jobs
by olalonde 2300 days ago
I've been getting into Rust lately and really enjoying it so far. Coming from JavaScript, It can feel a bit verbose at times and I'm still trying to get an intuitive grasp of ownership but it feels like a really small cost compared to say C/C++. A nice bonus is that it has very good support for WebAssembly/Node.js which makes it easy to start using Rust for some JavaScript modules without having to re-write the whole codebase. And finally, the community is still very noob-friendly.
2 comments

> It can feel a bit verbose at times

Certainly can, especially compared to JavaScript. The way I've come to view this (and across more languages than just Rust) is that it's a trade-off between providing more information to the compiler which it can use to catch errors, and verbosity. You can't provide the information without some input, though things like type inference can help cut down on this. IMO, it's worth it: my Rust code, once it compiles, I feel has less bugs than my equivalent Python; I'd rather fight with the compiler than with runtime exceptions.

As I've learned Rust, I also find that sometimes you can elide some parts of things. E.g., in collect() calls, you can say Vec<_>, eliding the item in the Vec, because the iterator you're collecting it from already knows it, and it can be inferred from that.

Of course, sometimes, I think it's nice to provide the type anyways, as I find the compiler is better at inferring than I am. I've definitely spent a fair amount of time in Python looking at a variable and wondering what type IS this?

I felt the same, coming from JavaScript and Python. Then I realised "verbosity" is actually "the language demanding you be crystal clear about what you're asking and that every code path is covered."

I just can't go back. Typescript gives me most of this. But Python feels just awful to me now. It's like an entire kind of cognitive load is being eliminated from my day.

I’ve had some luck with Mypy, but it’s still very bolted-on. Even getting the type checker to find dependencies installed on your system is nontrivial. But this sort of tedium is just par for the course with Python.