5 ms·
I think one of the biggest benefits of Rust is it bakes in static analysis of code as a first class feature. Which means the language is amenable to analysis an
by ChrisSD 7y ago
I think one of the biggest benefits of Rust is it bakes in static analysis of code as a first class feature. Which means the language is amenable to analysis and you don't have to use third party tools to benefit from it.
I also like some of the abstractions. They're clever in their simplicity. For example, an iterator over an array or vector is simply doing a for loop using pointers.
- Waterluvian 7y agoI'd like to understand what you mean by baked in. Not only does vscode need a plugin, it needs a language server running to do the static analysis. Are there analysis capabilities without the language server?
- UK-Al05 7y agoThe compiler by its self can do it, if you run it. I believe the language server is just for real time editor integration.
- Waterluvian 7y agoGotcha, thanks. This is too tangential to belong here. I need to go better understand what exactly the language server is doing if the compiler is able to provide all the details. Going to guess it has to do with partial/progressive analysis and supplying a programmatic interface to convert errors/warnings into squiggly lines rather than text output.
- steveklabnik 7y ago> I need to go better understand what exactly the language server is doing if the compiler is able to provide all the details. Converting it from what the compiler knows to the https://langserver.org/ https://langserver.org/ protocol. The long-term goal is to have the compiler be able to do this directly, but there's some stuff to do in the meantime.
- orf 7y agoI believe he means that certain things that would need static analysis in other languages are impossible to do as part of the type system. For example match statements need to be exhaustive. Your program won't compile unless they are.
- johannes1234321 7y agoNot Impossible, but have to explicitly makred as "unsafe"
- Sevii 7y agovscode requires languages to implement a language server. It doesn't have anything to do with rust.
- seren 7y agoThe other important aspect is that even if you have a static analyzer available, people might not be able to afford them (Coverity/klockwork/etc licenses) or even if they have it, there is nothing preventing them from skipping the analysis (just for this one time, I promise). (Another trick is to run the static analyizer, and not fixing the issues found...) With Rust the compiler is already providing a lots of analysis, and you can't easily skip it. And if you do by using unsafe{}, it shows. So basically, even if your dependencies are provided by the worst team in the world, you know that the guarantees enforced by the Rust compiler are in the code. (To be fair, it does not mean that the SW will do anything useful, but it won't likely segfault)
- pron 7y agoYes and no. It provides some kinds of (important!) static analysis out of the box, but at the cost of complexity, which directly adversely affects some other kinds of (also important) static analysis. For example, there are sound static analysis tools that guarantee no undefined behavior of C code, but AFAIK, such tools can at best only work on a subset of C++, because of its complexity. Rust goes all out on eliminating undefined behavior, and may well be the best way of doing that in low-level programming, but eliminating UB is just a means to an end, UB is not the only source of dangerous bugs, and if the cost of eliminating it is high it may not be the best way overall of reducing bugs in low-level languages.
- amelius 7y agoAlso, ownership checking only seems to work well for tree-like datastructures, but implementing something with cycles (back-pointers) immediately leads to nasty problems.
- zozbot234 7y agoThat's not a problem with Rust, it's a problem with back-pointers. You basically just need to fall back on raw pointers and do all the correctness checking yourself, precisely because the ownership model is not that helpful here. (Although if there is a pattern of "owning" references which involves no cycles plus back-pointers that are actually identifiable as such, that is directly supported via Rc<> and Weak<>.)
- deleted 7y ago[deleted]
- mcqueenjordan 7y agoWhat is the complexity, and what are its costs? As an active user of Rust, I haven't seen the (adverse) complexity or its costs yet. It's worth pointing out that Rust combats more than undefined behavior. Undefined behavior is a category of bad things that Rust works to eliminate, but Ownership goes beyond eliminating UB, and eliminates a large swath of potential logic bugs.
- amelius 7y ago> it bakes in static analysis of code as a first class feature. This is basically what all type checking does. It's not specific to Rust.
- dralley 7y agoRust brings more to the table than just the standard static type checking, you're selling it short. The borrow checker is unique to Rust. So is compiler enforcement of only allowing thread safe data structures to cross thread boundaries. Both of those are a pretty big deal.