4 ms·
That sounds… bad? The whole point of rusts type system is to try to ensure safe memory usage. Opinions are opinions, but if I’m letting my runtime handle memo
by dartos 3y ago
That sounds… bad?
The whole point of rusts type system is to try to ensure safe memory usage.
Opinions are opinions, but if I’m letting my runtime handle memory for me, I’d want a lighter weight, more expressive type system.
- School-Cotton 3y agoI’m assuming by rust’s type system they mean without lifetimes. In which case it’s existed in lots of GC languages (OCaml, Haskell) but no mainstream ones. It isn’t really related to needing a GC or not.
- gpderetta 3y agoYou still want RAII and unique references, but rely on GC for anything shared, as if you had a builtin refererence counted pointer. I do also believe this might be a sweet spot for a language, but the details might be hard to reconcile.
- School-Cotton 3y agoI haven’t used Swift so I might be totally wrong but doesn’t it work sort of like you describe? Though perhaps with ARC instead of true GC, if it followed in the footsteps of Objective-C.
- gpderetta 3y agoPossibly, yes. I haven't used swift either though. Does it have linear/affine types? Edit: I would also prefer shared nothing parallelism by default so the GC can stay purely single threaded.
- dartos 3y agoWithout lifetimes, Pins, Boxes, Clone, Copy, and Rc (Rc as part of the type itself, at least)
- afavour 3y agoI like Rust’s type system just fine but for me it’s types combined with language features like matching that draw me to Rust. When I was still learning I made an entire project using Arc<> with no lifetimes at all and it was actually a great experience, even if it’s not the textbook way to use Rust.
- sanderjd 3y agoHonestly, I think syntax for Arc (and/or Rc or some generalization of the two) and more "cultural" support for writing in that style would have benefitted rust back when 1.0 was being finalized. But I think the cow is out of the barn now on what rust "is" and that it isn't this.
- cmrdporcupine 3y agoYes, if you think about it, it's a bit weird that async gets first syntactical class treatment in the language but reference counting does not. A similar approach of adding a syntactical form but not mandating a particular impl could have been taken, I think. Same for Box, but in fact Rust went the opposite way and turfed the Box ~ sigil. Which I actually feel was a mistake, but I'm no language designer.
- zozbot234 3y agoAsync has to get first-class treatment in the syntax because the whole point of it is a syntax-level transformation, turning control flow inside out. You can also deal with Future<> objects manually, but that's harder. A special syntax for boxed variables adds nothing over just using Box<> as part of the type, similar for Rc<> (note that in any language you'll have to disambiguate between, e.g. cloning the Rc reference itself vs. duplicating its contents, except that Rust does it without having to use special syntax).
- sanderjd 3y agoYeah, but personally I think Rc/Arc is more deserving of syntax than Box!
- 3y ago
- wongarsu 3y agoRust's type system prevents bugs far beyond mere memory bugs. I would even go as far as claiming that the type system (together with the way the standard library and ecosystem use it) prevents at least as many logic bugs as memory bugs.
- dartos 3y agoThe type system was built to describe memory layouts of types to the compiler. But I don’t think it prevents any more logic bugs than any other type system that requires all branches of match and switch statements to be implemented. (Like elm for example)
- speed_spread 3y agoIt prevents a lot more than that. For example, it prevents data race conditions through Send/Sync traits propagation.
- kaba0 3y agoBesides preventing data races (but not other kinds of race conditions), it is not at all unique. Haskell, OCaml, Scala, F# all have similarly strong type systems.
- sanderjd 3y ago> The whole point of rusts type system is to try to ensure safe memory usage. It isn't though. The whole trait system is unnecessary for this goal, yet it exists. ADTs are unnecessary to this goal, yet they exist. And many of us like those aspects of the type system even more than those that exist to ensure safe memory usage.
- dartos 3y agoIt is the first and foremost goal of every language choice in rust. I think traits muddy that goal, personally, but their usefulness outweighs the cost (Box<dyn ATrait>) I should’ve probably said “the whole point of rusts type system, other than providing types and generics to the language” But I thought that went without saying
- sanderjd 3y ago> It is the first and foremost goal of every language choice in rust. It ... just ... isn't, though. I mean, I get what you're saying, it's certainly foundational, Rust would look incredibly different if it weren't for that goal. But it just isn't the case that it is "the first and foremost goal of every language choice in rust". I followed the language discussions in the pre-1.0 days, and tons of them were about making it easier and more ergonomic to create correct-if-it-compiles code, very often in ways that had zero overlap with safe memory usage. Traits don't "muddy that goal", they are an important feature of the language in and of themselves. Same thing with the way enums work (as arithmetic data types), along with using Option and Result for error handling, rather than exceptions. Same thing with RAII for tying the lifecycle of other resources to the lifecycle of values. The memory safety features interact with all these other features, for sure, and that must be taken into account. But there are many features in the language that exist because they were believed to be useful on their own terms, not in subservience to safe memory usage. And it's not just about "providing types and generics to the language", it's a whole suite of functionality targeted at static correctness and ergonomics. The ownership/lifetime/borrowing system is only one (important!) capability within that suite.
- BWStearns 3y agoThe whole reason I got interested in Rust in the first place was because of the type system. I viewed it as "Haskell types but with broad(er) adoption". The fact that it also has this neat non-GC but memory safe aspect was cool and all but not the main sell for me.
- happens 3y agoBy "rusts type system" I mean enums with exhaustive pattern matching and associated structs, generics, conventional option and results types, and so on. None of that necessarily has anything to do with lifetimes as far as I understand.