Earlier quoted context omitted.
> Now, this is a contrived example, and would better be written with `if let` in today's Rust, but this is the _kind_ of situation in which unwrap is totally, 100% cool, but the compiler can't know. If the author knows it's safe, they should be able to express how they know in a way that the compiler can understand. Certainly I think there's a large space of use cases where the extra guarantee provided by forbidding…
What if I want to have a reference to the last element in a vector that I just pushed? Without a push method that immediately returns such a reference, this will always involve an unwrap. And this is not just some weirdly constructed example, I've needed to do this in real code a couple of times already.
Rust and the Future of Systems Programming [video]
441–450 of 511 posts
Re: Rust and the Future of Systems Programming [video]
#442Earlier quoted context omitted.
> IMO it would be great to get folks who write the enormous base of existing realtime apps driving critical devices everywhere to sit up and take notice of Rust. It would, and definitely should, move into the direction of safer languages than C. The biggest problem I see is tooling and legacy. Tooling, because there's a ginormous amount of testing and design software that "works with C" (whatever that means in the co…
> because everyone already has their 20 year old [C] codebases It's comments like these that remind me how exclusionary the software world is. Your definition of "everybody" is such a tiny number of people. But that's who you have in mind when you are constructing the world around you each day.
Second, I was responding to a comment talking about "existing, critical, real time applications". Of which a huge number of cases do have existing, very old legacy codebases.
Third, I fail to see what you tried to bring to the conversation. If your only problem was with my rhetoric, see above.
Re: Rust and the Future of Systems Programming [video]
#443Earlier quoted context omitted.
Yeah, but why ? I've never used a libc on embedded, and I'm kind of confused as to why you'd want to. Am I just Doing It Wrong™?
Atleast for avr-gcc, (part of) startup code and vector table layout come from avr-libc. I'm kinda surprised you got by without libc - no strxxx, memxxx ,xxxprintf/no math.h functions ever?
Re: Rust and the Future of Systems Programming [video]
#444Earlier quoted context omitted.
> So wait, what more does Rust's static analyzer give us again? Does it somehow remove the need for refcounting heap objects? Refcounting is rarely needed because most sharing is done via "borrows", which usually work via scope-tied "references" which may point to either the stack or the heap. Implementing and enforcing local scope pointers in C++ via static analysis is not hard. Making it possible to thread borrows…
> Right, but at this point you have a very weird looking subset of C++ It's a little weird looking at first glance, but ultimately it's not really that weird. The main unfamiliar thing is that objects that are going to be the target of a (safe) pointer need to be declared as such. So { std::string s1; auto s1_ptr = &s1; } becomes { mse::TXScopeObj s2; auto s2_ptr = &s2; } s2 acts just like a regular string. It's just…
Your proposal was to take Rust's static analysis and make it work with C++. It's clear you don't know Rust. Why are you so confident about what kind of effect that would make on the language? Rust is not "like C++ but with more static analysis", it's a very different language. A lot of the safety that modern C++ gets you is something that Rust gets you, using different mechanisms.
> Sure it can, that's the point. For example:
This example seems to be a SaferCPlusPlus example? I'm talking specifically about your proposal to take Rust's static analysis and use it on C++. That isn't what SaferCPlusPlus seems to be doing. It seems like you might be talking about something else? The general applicability of safety based static analysis? I'm not arguing with that.
> My impression is that Rust has been evolving a lot. Is the language stable now?
Still evolving, just like C++ is, but is stable now. Has been for more than a year.
> Are we happy with Rust's solution for exceptions?
I am. Most folks in the Rust community are. There are no missing pieces now, though.
> Has it vanquished D as the successor to C++?
No, and that's subjective, and your C++-with-Rusts-static-analysis will not be in a different boat.
> I'm still stuck with existing C++ projects. And I'd feel better if they were (at least mostly) memory safe.
That's my point. The amount of work to convert existing C++ code to something that satisfies a static analyzer using Rust's exact set of invariants is just as much as the work required to convert to Rust. You won't be able to just throw a new static analyser at C++ code and stuff will magically work. It will require significant refactoring and effort. Nor will your code be able to easily talk with other C++ libraries.
> Umm, it could be automated
No, "human intervention" I said. It can't be automated easily, because the style it enforces is significantly different. I've done quite a bit of jumping back and forth between C++ and Rust these days (in the same codebase, with FFI), and the fact that the structure and style of programs is different is very apparent.
There is work on translating C to Rust (and might grow to C++ some day?), but IIRC you still need significant human intervention. For C at least there is no existing safety system to replace, so it's still easier, but translating from C++s (largely incompatible) existing safety system will be tough.
Translating code will need the translator to figure out what the code is trying to do, basically. This isn't like Python2->Python3. Like I said, the style enforced is different. I don't mean syntax style, I mean how code is structured at a higher level.
> I mean you're supposed to try to avoid pointers in favor of standard containers and iterators
If you want to be 100% safe you need to solve iterator invalidation and Rust's solution is something that is very hard to make work with C++s usual style of coding. If you want to avoid all unnecessary allocations and refcounting you need a lifetime system. To use Rust's model the mechanism of moving would have to be tweaked considerably.
Again, these problems can probably be solved organically from C++ itself (which I guess is what SaferCPlusPlus is doing?), building a static analyser that tries to solve them building on the existing mechanisms in C++. But importing Rust's analysis will just get you a completely new language which has almost no use.
Re: Rust and the Future of Systems Programming [video]
#445Earlier quoted context omitted.
Right, so you implement them with unsafe. While you can implement doubly linked lists safely with refcounting, you're perfectly free to implement them with unsafe code. This is what unsafe code is for , designing low level abstractions with clean API boundaries. (Also I don't see how this is relevant at all)
Right, so you implement them with unsafe. If you need unsafe code for basic operations within the language, something is wrong with the language. This isn't about talking to hardware, or an external library. It's pure Rust code. (Some pointer manipulations can be built from swap as a basic operation. That may work for doubly-linked lists. The other big problem is partially valid arrays, such as vectors with extra spa…
I have helped design a low level data structure exactly twice. In both cases, this was a highly custom concurrent data structure, which would have been even harder to get right in C++ or some other language.
If you need a regular run-of-the-mill datastructure it will exist in the stdlib or crates ecosystem. This is not a "basic task". Just because schools teach it early does not make it a "basic task". It's a task that needs to be done at some point, but doing it once and making it part of the stdlib or a crate is all that is necessary. It has become a "basic task" in C++ because it's easy enough to do that you don't need to reach for the stdlib, but that doesn't mean that it's necessary to have a bespoke implementation of a DLL that often in C++; usually the stdlib one will do.
The same "too many lists" book you linked to explains why DLLs are niche datastructures on the first page (singly linked lists can be implemented safely in Rust, though they can be somewhat niche too).
Re: Rust and the Future of Systems Programming [video]
#446Re: Rust and the Future of Systems Programming [video]
#447Earlier quoted context omitted.
> So wait, what more does Rust's static analyzer give us again? Does it somehow remove the need for refcounting heap objects? Refcounting is rarely needed because most sharing is done via "borrows", which usually work via scope-tied "references" which may point to either the stack or the heap. Implementing and enforcing local scope pointers in C++ via static analysis is not hard. Making it possible to thread borrows…
> > Why? The static analyzer has an opinion on whether or not a program is safe. The optimizer just wants to know if it still thinks it's safe when you remove a runtime check. > I guess I misunderstood your proposal. This sounds doable. But, again, you'd be using a weird subset of C++ that doesn't seamlessly integrate, and you're just better off using Rust at this point. My proposal is sort of language independent. I…
It's hard to beat a modern, tuned GC.
Re: Rust and the Future of Systems Programming [video]
#448I keep trying to learn rust but fail miserably. They do say on their website that there's a hump that you have to climb over before everything fits into place, which is probably applicable to everything you'll learn, but sometimes I think that hump is too much of a hurdle
A good language should be like a good game: easy to learn, hard to master. We don't care about expert cases, we only care about getting productive ASAP, which means having students hoping into a language and learning it quickly. Solving the details is easy: just teach coding discipline and enforce good practice and do code reviews, and discourage "throwable" code. Security is not only the job of a programmer, it has…
Re: Rust and the Future of Systems Programming [video]
#449Earlier quoted context omitted.
So, since we're talking about Rust... print!("You have %d new messages", messages) Was that supposed to make me want to abandon all type safety and embrace a GC'd language that runs in a VM?
There are advantages to GC, even Rust has runtime GC. But where is the memory freed ? You don't have to think of that at all in JavaScript. Also when something goes wrong with types in JavaScript the worst case scenario is "2"+2 turns into "22" witch is easy to avoid, compared to a silent overwrite/overflow. Even if the types in JavaScript is very loose, they are much safer.
> even Rust has runtime GC
Only in an extremely narrow sense; there's no tracing GC, only reference counted types. And they're not used very often.Re: Rust and the Future of Systems Programming [video]
#450Earlier quoted context omitted.
> You can't have reasonable value types that own resources if you need explicit error checking. The proper place for the period in that sentence is before the "if"; owning resources is not a reasonable thing for a value type to do.
Tell me more about how std::string is unreasonable.
In Rust, std::string::String is not a "value type", and by that, I mean it's not Copy.