Someone just re-invented discriminated variants from Pascal.
This seems to have become quite prevalent. Apparently the majority of CS degrees don't teach history of programming languages. On my language design lectures in the mid-90's we had to learn all major ones, all the way back to Fortran.
Type-Safe Unions in C++ and Rust
81–90 of 140 posts
Re: Type-Safe Unions in C++ and Rust
#82Earlier quoted context omitted.
Like steveklabnik, I'm extremely curious to hear more about how Smalltalk's concurrency model is just like Rust's. The latter is a fairly flexible model to defend against data races (which seems to be a concept only really formalised in the late 80s) that puts most of the power in the programmer's hands (i.e. no need for compiler-inserted locks on every object, etc.) that comes from a finely balanced combination of t…
"which seems to be a concept only really formalised in the late 80s" http://brinch-hansen.net/papers/1975a.pdf http://brinch-hansen.net/papers/ His first, concurrent OS was RC 4000 in 1969. It had many mechanisms in place. He got the key parts of the safety problem figured out by 1972. His language to handle much of it statically at compile-time was done in 1975. His Boss 2 system same year used coroutines + similar…
Some relevant lines:
> A Concurrent Pascal compiler will check that the private data of a process only are accessed by that process. It will also check that the data structure of a class or monitor only is accessed by its procedures
is significantly less than what Rust provides, because:
> Processes cannot operate directly on shared data. They can only call monitor procedures that have access to shared data. A monitor procedure is executed as part of a calling process (just like any other procedure).
> If concurrent processes simultaneously call monitor procedures that operate on the same shared data these procedures will be executed strictly one at a time. Otherwise, the results of monitor calls would be unpredictable. This means that the machine must be able to delay processes for short periods of time until it is their turn to execute monitor procedures. We will not be concerned with how this is done, but will just notice that a monitor procedure has exclusive access to shared data while it is being executed.
Rust allows shared access to immutable data and does not require either serialization or the invocation of a virtual machine; it also allows nondeterministic operation to be used as long as it cannot cause memory unsafety.
Additionally, there are other, more basic things that the system is not capable of. For instance:
> (Strictly speaking, a compiler can only check that single monitor calls are made correctly; it cannot check sequences of monitor calls, for example whether a resource is always reserved before it is released. So one can only hope for compile time assurance of partial correctness.)
A major part of what Rust brings to the table is the ability to statically avoid problems like use after free and double free even in a concurrent setting. How would I avoid resource leaks in a system like this without a per-thread allocator (which would likely prevent sending across threads)?
Of course, it's not clear to me that this matters anyway, since I can't destroy a thread or shared data structure!
> Dynamic process deletion will certainly complicate the semantics and implementation of a programming language considerably. And since it appears to be unnecessary for a large class of real-time applications, it seems wise to exclude it altogether. So an operating system written in Concurrent Pascal will consist of a fixed number of processes, monitors, and classes. These components and their data structures will exist forever after system initialization.
I agree that people have a strong tendency to not know what past work has been done, and Concurrent Pascal is admirable, but what Rust does is not the same thing. Rust specifically tackles a lot of hard problems in concurrency that simply do not exist as long as you (1) assume away deallocation for shared data structures, and (2) serialize all access to those data structures.
(There are lots of other specific points I could go into; for instance, Concurrent Pascal apparently lacks facilities for generic programming, so I probably couldn't combine two correct concurrent data structures and expect a third correct concurrent data structure to come out. But that stuff isn't directly related to concurrency).
Re: Type-Safe Unions in C++ and Rust
#83Earlier quoted context omitted.
I think you're reading into the comment too much. Rust by definition, will create a safer variant of whatever similar code you write in C or C++. This isn't really debatable, things like bounds checking on arrays, strongly typed error results, thread safe memory sharing semantics. These will absolutely guarantee that in general you will have safer code in Rust. What I said is that it might take you longer to write it…
Ah, I see now. Thank you for clarifying. Not that I agree entirely, mind, just that your initial comment was clarified.
Re: Type-Safe Unions in C++ and Rust
#84Earlier quoted context omitted.
For pattern matching, that's true. And my response is, stay tuned. C++ has a lot more to offer in this area in the future. std::variant is opening a big door for all kinds of new features in the language, and for those who cannot wait, there are pattern matching libraries out there to peak at.
I feel like this point is often made about C++: "in the future we will have that feature too!" If you don't want to wait, want to experiment with something else, learn a new language, etc., Rust is awesome. Obviously the counter argument to this is, "but there's 30+ years of C++ in production", but be honest, who actually wants to work on a 30 year old codebase?
Why do I have to wait for every compiler on every system I want to build on to update to some future standard when things could be done now across the board in many cases?
Re: Type-Safe Unions in C++ and Rust
#85Earlier quoted context omitted.
Ada and Pascal are not really research languages, though. But still, there are improvements taken from research, see Ada 2012 contracts for example.
sorry if this is a dumb question, but what classifies a language as a research language?
If you hear the term used disparagingly it's because they tend to have issues you generally wouldn't want to put up with when you're on the clock: compiler bugs, lack of error messages, large missing pieces in the standard lib, spectacularly bad performance, etc because those weren't the problems the language was meant to explore.
Re: Type-Safe Unions in C++ and Rust
#86Earlier quoted context omitted.
One interesting thing about Rust is that none of the language features are really new . Even the borrow checker is from research papers and languages from quite a while ago. The only thing I can think of that might be truly unique to Rust is the concurrency safety model (Send+Sync), though that might be old too. Rust has just managed to take all these features and put them together well, and strive to be more than a…
the concurrency safety model (Send+Sync), though that might be old too Smalltalk has had that since the early 1980s
Re: Type-Safe Unions in C++ and Rust
#87Earlier quoted context omitted.
One interesting thing about Rust is that none of the language features are really new . Even the borrow checker is from research papers and languages from quite a while ago. The only thing I can think of that might be truly unique to Rust is the concurrency safety model (Send+Sync), though that might be old too. Rust has just managed to take all these features and put them together well, and strive to be more than a…
Putting them well together in Rust is debatable. Writing proper and safe concurrent code in Rust still looks horrible compared to languages which supports it natively in the type system, e.g. ponylang type capabilities. You still have to manually maintain locks, and it's also much slower. There's a safety model, but it's only best practice, not enforced by the language nor the compiler. So calling it "safe" and "trul…
What? How is it not enforced?
> You still have to manually maintain locks, and it's also much slower.
Slower? I don't think it can be any faster even in theory!
Re: Type-Safe Unions in C++ and Rust
#88Is there any demand for a syntactic sugar layer on top of C++? Something to make these new features more ergonomic? Something one could opt-in to for newer code, or code that doesn't need to be backward compatible to 1990? Something that outputs valid C++ and so works with any tool chain?
Don't compile to C.
Re: Type-Safe Unions in C++ and Rust
#89> but it’s the first language I’ve experimented with that has made them a first-class feature It is a feature of ALGOL68, Pascal, Ada and quite some newer languages: https://en.wikipedia.org/wiki/Tagged_union
One interesting thing about Rust is that none of the language features are really new . Even the borrow checker is from research papers and languages from quite a while ago. The only thing I can think of that might be truly unique to Rust is the concurrency safety model (Send+Sync), though that might be old too. Rust has just managed to take all these features and put them together well, and strive to be more than a…
Eh, that's underselling Rust's contributions. Rust is more flexible than anything I know of when it comes to enforcing aliasing-xor-mutability. Cyclone for example was much more restrictive in disallowing aliasing (see Grossman's "Existential Types for Imperative Languages").
The key feature that Rust has is flow-sensitive permissions on unique loan paths, which is actually pretty novel as far as I'm aware.
Re: Type-Safe Unions in C++ and Rust
#90Earlier quoted context omitted.
the concurrency safety model (Send+Sync), though that might be old too Smalltalk has had that since the early 1980s
Smalltalk is dynamically typed. How can it have a static type system feature?