5 ms·
Swift is memory safe. It’s the better C++ I want, just out of reach because Apple. There is at least one memory safe alternative to Rust that doesn’t require a
by lll-o-lll 4y ago
Swift is memory safe. It’s the better C++ I want, just out of reach because Apple. There is at least one memory safe alternative to Rust that doesn’t require a GC.
I’ve made this argument before but here we go again. GC is great and works better and faster than reference counting in most cases, but there are degenerate cases and they matter on phones. One degenerate case is memory pressure. A GC running out of memory will perform terribly. Another case is bounded latency. Most obvious with hard real-time, but also a problem for any system where a long GC pause will lead to failure modes or user dissatisfaction. RC allows for predictable (albeit slower) performance.
So if we can agree that “no GC” is preferable in a constrained environment like a phone, but you still want memory safety, then you are left with “is Swift or Rust better for productivity?” It’s pretty obvious that the answer is resoundingly “Swift”.
- zozbot234 4y agoUbiquitous ARC has even worse performance than tracing GC. Only Rust gives you complete memory safety with fine-grained control over memory management strategy.
- lll-o-lll 4y agoSwift has some tricks to make things faster than naive ARC, but the point is that you trade a little speed for deterministic behavior. The post I was replying to was making the argument I see frequently. That if not Rust, you should go GC. This is simply wrong. The degenerate GC cases can be avoided with Swift. It’s better for a phone application in nearly every case. If it wasn’t bound to Apple, I’d say it’d be a better choice than Rust in 90% of the places Rust is used. Rust has its place, but the idea that it’s the obvious and only replacement for C++ is overblown. A language like Swift seems like a better path forward.
- pjmlp 4y agoRust isn't the only one with affine types, only the one that has managed more mindshare.
- Jweb_Guru 4y agoNone of the other languages you're thinking of are particularly usable as industrial strength languages for general purpose programming, for reasons that go way beyond mindshare.
- pjmlp 4y agoMind reader?
- Jweb_Guru 4y agoI don't need to be a mind reader because I know which languages other than Rust support sound affine types. They broadly fall into three categories: * Languages with comprehensive support for affine types, but that are otherwise too limited to be really useful for general purpose programming. Usually this is due to a lack of industry support. * Languages with bolted on support for affine types where you can't get consistent performance benefits out of code written in that style and it's very difficult to write and compose code written in that style. * Complex languages with advanced type systems that can emulate affine types, and are extremely powerful, but are borderline unusable for any purpose. Like I said, whichever of those three language categories you're thinking of, my reasoning applies. No mind reading necessary! I understand though that you believe safe concurrency has been solved since Modula 3 because you can just lock every object while it's in use (why didn't anyone else think of that?), so maybe you don't really appreciate the vast gulf in usability between affine types in these kinds of languages and in Rust.
- pjmlp 4y agoSee you don't know which languages I mean. I never said such thing about Modula-3, but I do believe indeed that Rust doesn't solve the concurrency problem when accessing external resources in distributed computing. It is nice it has an answer for data concurrency for internal in-memory data structures, that is a tiny slice of solving distributed computing access patterns. Like those languages that you "know", Rust's place is being specialized on deployments where no form of automatic memory management is allowed.
- jasmer 4y ago"Only Rust gives you complete memory safety with fine-grained control over memory management strategy." Yes, and it comes at a cost. Pay that cost for those advantages if necessary. Otherwise, use something else.
- pcwalton 4y agoReference counting is a form of garbage collection, and therefore Swift is a GC'd language.
- deleted 4y ago[deleted]