Something something history is a flat circle
Something something history is a flat circle
I don’t use Rust much, but I agree with the thrust of the article. However, I do think that the borrowchecker is the only reason Rust actually caught on. In my opinion, it’s really hard for a new language to succeed unless you can point to something and say “You literally can’t do this in your language”
Without something like that, I think it just would have been impossible for Rust to gain enough momentum, and also attract the sort of people that made its culture what it is.
Otherwise, IMO Rust would have ended up just like D, a language that few people have ever used, but most people who have heard of it will say “apparently it’s a better safer C++, but I’m not going to switch because I can technically do all that stuff in C++”
“apparently it’s a better safer C++, but I’m not going to switch because I can technically do all that stuff in C++”
The main difference between C++ and D was that (for most of the time in the past) D required garbage collector.
So, D was a language with similar Algol-style syntax targeting a completely different niche from C++.
Trying to correct your quote, it should read something like “I’m not going to switch because I can’t technically do all that stuff in D that I’m doing in C++” for it to make any sense.
“Before rust you could either have a fast language (C/C++) or a memory safe language (any other language. That is, languages with garbage collector).”
Ada managed to do safe and fast over forty years ago.
I’ve never used Rust but from my very cursory knowledge of what the borrow checker entails, it wouldn’t add so much to Ada.
Use of pointers is already strongly discouraged by the simple fact that the language is designed to rarely truly need them. Besides, the compiler itself chooses automatically whether to pass data by value or by reference depending on the required results and what is most efficient. You can also specify parameters passed to a function as read-only. Finally, another thing that Ada does to prevent yourself shooting in your foot is to enforce strong encapsulation of functions and data.
Overall, one way to put it in simple terms is that Ada requires the programmer to give enough information to the compiler so as to ensure that it actually outputs what you want it to, which as far as I understand, is sort of what the borrow checker is there for. The downside to the Ada approach is that it is very verbose, but with the kind of code editing capabilities we have nowadays it’s certainly not as much a hassle as it was when Ada came out.
Anyways, I suspect that both languages are different enough in overall paradigm that trying to solve problems in Ada the way you would in Rust would probably be quite frustrating and give rather poor result.
The borrow checker is a lot deeper than merely making pointer use a bit safer; it provides a model for data ownership based on affine types.
Also, to the extent that “Ada requires the programmer to give enough information to the compiler so as to ensure that it actually outputs what you want it to,” if I understand you correctly, that is basically true of every language with a static type system. At the extreme end, we have dependently typed languages which essentially let you express arbitrary mathematical propositions in your types and, if the program compiles, then you know that they will always be satisfied without having to do any checks at runtime.
I kinda disagree. The reason rust caught on is because it is much safer than C++ while having the same or even better performance. And in some contexts, being garbage collected means bad performance.
Before rust you could either have a fast language (C/C++) or a memory safe language (any other language. That is, languages with garbage collector). But if you required memory safety and peak performance, there wasn’t any option.
Yes, the reason that rust is both memory safe and fast is because it has a borrow checker. But the borrow checker is the means, not the end.
unsafe blocks.
Null safety and memory safety are different features.
Null safety means that you cannot access a struct’s fields without first checking if the pointer to that struct isn’t null. And this must be a compile-time check.
Memory safety means that you cannot read or write to/from memory that has been free-ed. Without leaks ofc, otherwise it would be very easy.
How can you not have memory-safety while also having a garbage collector?
Garbage collection means that all objects live as long as you have a reference to it. Which means that you can only dereference a pointer to invalid memory if you willingly create an invalid pointer, or reinterpret the type of one pointer into another. Going out of bounds of an array counts as the first case.
If a language has garbage collection but no compiler/interpreter supports it, then the language doesn’t have garbage collection.
As I said, I don’t consider going out of bounds of a buffer a memory safety issue. Forcing the programmer to handle an out-of-bounds case every time there is an array access can be incredibly tedious. So much that not even rust forces you to do so. And if that language has iterators, it’s even less of an issue.
I consider out-of-bounds array access to same as casting a pointer to another type. Just because a language lets you do it, it doesn’t mean that it is not memory safe. It is a performance feature, since checking the bounds every time is always possible (and incredibly easy to implement), but also with too big of an impact when you could just check the length once per loop instead of per loop iteration.
get_unchecked, which is unsafe.
Rust has monomorphisation like C++ and every function has the aliasing guarantees of restrict, a keyword rarely seen in C code bases use and C++ doesn’t even support.
This means you can get more optimisations while writing in an intuitive style, where C/C++ requires some changes to the code.
On the other hand rustc has some hiccups with argument passing and rvo. One could argue that that’s just the compiler while the aliasing problems are part of the language in the C/C++ case, but while there is only one rust compiler its performance is the languages performance.
For most use cases they are about equally fast.
D has a lot of other reasons why it haven’t caught on.
int meaning different things in both languages), and nowadays I can pull the conversion off on the regular. It’s like the only changes that were made to the language are making things more consistent, making things work better. etc. Rust is more like a language that is a marriage between C-style languages and OCaml. Rust is also a “functional first” language with the ability of opting out from the functional part, first when I’ve heard about Rust it was through this “fancy and new programming paradigm, that promises to fix everything wrong with programming”, and the D team wanted to be left out from making const the default mutability.@nogc thread going (using that for audio).moving from D1 to D2
I was learning a few different languages at the time, and it’s a bit fuzzy in my head, but I remember the confusion between the 2 compilers. One was incomplete and/or obsolete, and the other one was in beta or something and you shouldn’t use it anyway. I chose nothing and tried something else because it was annoying to watch. Walter, as the BDFL, should have decided on something but it never arrived, and the hype went away.
All I remember is that some Japanese guy wrote a bullet-hell library and game in D, and that was great. But the community was too confusing for me.