4 ms·
The borrow checker prevents code from running at all, sometimes even if the code would be perfectly safe (e.g. two slices to non-overlapping areas of a vector).
by dbrgn 10y ago
The borrow checker prevents code from running at all, sometimes even if the code would be perfectly safe (e.g. two slices to non-overlapping areas of a vector).
JavaScript on the other hand is full of quirks, but you get something to work quickly, even if it's buggy.
The huge advantage that Rust has over languages like JavaScript is that if it compiles, it's almost guaranteed to run (unless you have logic errors somewhere). I think that fact is greatly under-appreciated.
- pimeys 10y ago> The huge advantage that Rust has over languages like JavaScript is that if it compiles, it's almost guaranteed to run (unless you have logic errors somewhere). I think that fact is greatly under-appreciated. This. In my company, our Rust apps have a very small amount of tests, mostly integration tests written with Python. You need to test certain business logic, but mostly if it compiles, deploy all the things :)
- vog 10y ago"If it compiles, it works." You don't hear this often, but when you hear this, people a usually talking about either OCaml or Haskell. Nice to see Rust joining this club, too. I often rephrase this as: "When switching from Python(/Ruby/PHP) to OCaml(/Haskell/Rust) you notice how many of your unit tests were really just type checks."
- pimeys 10y agoBut then again, there are some gotchas. Runtime errors can happen when using unwrap like in every example around the Internet. I too used the unwrap everywhere when I started writing Rust, but soon realized that one must handle the results and everything can be an Err or None, even if you think it is not possible. I'd say beginner tutorials should UNDERLINE that the use of unwrap() is just for the first prototype and you must refactor them out to proper error handling.
- k__ 10y agoSure, but if you want to get correct software you have to learn about the language you're using. The borrow checker and quirks are just concrete manifestations of that fact.
- pimeys 10y agoBut when you have some months behind with daily Rust usage, basically the compiler just helps you to write correct code. I usually write code fast and then start iterating with the compiler to get everything right. If I need to fight too long with the borrow checker phase, I know my structure is wrong and I should rewind a bit and try again.
- k__ 10y agoI didn't want to say that JS' quirks are better than or equal than Rusts borrow checker. I just wanted to say people are hating on the borrow checker, while they gladly invest time in learning quirks and I don't understand why :)
- pimeys 10y agoBut I must say, I was also kind of upset the first couple of weeks when always getting errors whatever I tried to do with Rust. And spending lots of time fixing those errors. When you learn the style, it's very easy to work with, but the first two weeks were a massive slap to my overblown programmer ego... :D
- jackmott 10y agothis same tendency to run if it compiles exists in most/all statically typed garbage collected languages too though, with less cognitive overhead while coding (but more runtime overhead of course!) What will be interesting is if Rust proves to be, or can be made to be, a productive choice for programs where the runtime performance is not needed. At the moment I feel like it adds so much verbosity compared to other ML-based languages that it just isn't. But I do love performance, even if I don't need it :)
- gigatexal 10y agoI don't think Rust was meant to be a "quick" language for prototyping I think that's python.
- iopq 10y ago> JavaScript on the other hand is full of quirks, but you get something to work quickly, even if it's buggy. In my experience JS is the worst at NOT working. Because when one part of the application fails, the entire PAGE stops working. Buttons don't work anymore, dropdowns don't work, nothing works. And all of this is just one buggy line of code away.