5 ms·
Yes, that's a very common misconception. Of course, if your program compiles, that doesn't mean the logic is correct. However, if your program compiles _and_ t
by LtdJorge 10mo ago
Yes, that's a very common misconception.
Of course, if your program compiles, that doesn't mean the logic is correct. However, if your program compiles _and_ the logic is correct, there's a high likelihood that your program won't crash (provided you handle errors and such, you cannot trust data coming from outside, allocations to always work, etc). In Rust's case, this means that the compiler is much more restrictive, exhaustive and pedantic than others like C's and C++'s.
In those languages, correct logic and getting the program to compile doesn't guarantee you are free from data races or segmentation faults.
Also, Rust's type system being so strong, it allows you to encode so many invariants that it makes implementing the correct logic easier (although not simpler).
- wakawaka28 10mo ago>In those languages, correct logic and getting the program to compile doesn't guarantee you are free from data races or segmentation faults. I don't believe that it's guaranteed in Rust either, despite much marketing to the contrary. It just doesn't sound appealing to say "somewhat reduces many common problems" lol >Also, Rust's type system being so strong, it allows you to encode so many invariants that it makes implementing the correct logic easier (although not simpler). C++ has a strong type system too, probably fancier than Rust's or at least similar. Most people do not want to write complex type system constraints. I'm guessing that at most 25% of C++ codebases at most use complex templates with recursive templates, traits, concepts, `requires`, etc.
- simonask 10mo agoComparing type systems is difficult, but the general experience is that it is significantly easier to encode logic invariants in Rust than in C++. Some of the things you can do, often with a wild amount of boilerplate (tagged unions, niches, etc.), and some of the things are fundamentally impossible (movable non-null owning references). C++ templates are more powerful than Rust generics, but the available tools in Rust are more sophisticated.
- sunshowers 10mo agoNote that while C++ templates are more powerful than Rust generics at being able to express different patterns of code, Rust generics are better at producing useful error messages. To me, personally, good error messages are the most fundamental part of a compiler frontend.
- wakawaka28 10mo agoConcepts make it possible to generate very clear (even user-friendly) template errors.
- sunshowers 10mo agoTrue but you lose out on much of the functionality of templates, right? Also you only get errors when instantiating concretely, rather than getting errors within the template definition.
- aw1621107 10mo ago> but you lose out on much of the functionality of templates, right? I don't think so? From my understanding what you can do with concepts isn't much different from what you can do with SFINAE. It (primarily?) just allows for friendlier diagnostics further up in the call chain.
- wakawaka28 10mo agoYou're right but concepts do more than SFINAE, and with much less code. Concept matching is also interesting. There is a notion of the most specific concept that matches a given instantiation. The most specific concept wins, of course.
- aw1621107 10mo agoOh, interesting! I didn't know about that particular feature of concepts. I'll have to keep an eye out for potential places it can be used.
- irishcoffee 10mo ago> However, if your program compiles _and_ the logic is correct, there's a high likelihood that your program won't crash (provided you handle errors and such, you cannot trust data coming from outside, allocations to always work, etc). That is one hell of a copium disclaimer. "If you hold it right..."
- kibwen 10mo agoRust certainly doesn't make it impossible to write bad code. What it does do is nudge you towards writing good code to a noticeably appreciable degree, which is laudable compared to the state of the industry at large.
- irishcoffee 10mo agoRust is just a tool. It’s as fallible as any other tool. I wish we took it off the pedestal and treated it as such.
- steveklabnik 10mo agoAre all tools equal in all dimensions or can they be compared for fitness of purpose?
- estebank 10mo agoA hand saw, a table saw and a SawStop are all tools, but they have different characteristics even though they all are meant to cut the same wood.
- irishcoffee 10mo agoAda, C, and lisp are all tools, but they have different characteristics even though they are all meant to cut through the same problems.
- yuriks 10mo ago...yes?