4 ms·
The unique safety features of Rus are all about memory safety, which is not something you have to worry about at all in Python. I can only assume that the bug
by s17n 4y ago
The unique safety features of Rus are all about memory safety, which is not something you have to worry about at all in Python. I can only assume that the bug classes you are referring to would have been eliminated by using essentially any language with a type system.
- charrondev 4y agoI find Rust to have a particularly expressive type system, and a quite strict one to. Not all languages with type systems such have strict enforcement of mutability or null safety.
- masklinn 4y ago> I can only assume that the bug classes you are referring to would have been eliminated by using essentially any language with a type system. Rust has a very expressive type system[0], which you won't otherwise find before hitting the more functional and research-y side of things. Modelling data in terms of enums (sum types), move types (affine types), etc... makes it a lot more reliable and a lot less faillible as it just removes entire swathes of edge cases. See concepts like "making invalid states unrepresentable". [0] though it's still lacking in many ways, the more you get the more you want after all
- p1necone 4y agoOther than Rust the only other "pragmatic" language I can think of that has as much of a robust type system is Typescript. As you say anything else you'd have a hard time convincing the rest of your team to use.
- rowanG077 4y agoTypescripts type system is anything but robust. It's escape hatch build upon escape hatch. Don't get me wrong, it has to be like that due to it allowing gradual typing and essentially beeing a superset of js.
- toomanydoubts 4y agoI now introduce you to Haskell. Welcome to the dark side.
- nu11ptr 4y agoTo some extent, possibly, but it is a very rich type system, and does not have null which in and of itself gets rid of a set of errors. I also find Rust culture tends to be more guarded on panicking due to having such a rich error type (Result), so panic is reserved for the worst possible "can't continue" scenarios (unlike languages with unchecked exceptions). Also, enum pattern matching is exhaustive which gets rid of errors where you simply don't account for new variants. The list goes on and on.
- stouset 4y ago> I can only assume that the bug classes you are referring to would have been eliminated by using essentially any language with a type system. That's not entirely true. As an easy example, Go has a type system but it's relatively anaemic and recreates the "billion dollar mistake" of nil. I have personal experience with Go applications that have broken in production due to nil dereferences, to bugs related to type-switching off `interface{}`, and to the language's inability to enforce exhaustive case statements in general. While the unique safety features in Rust are generally about memory safety, it still takes a much more safety-conscious approach in general than most languages that are statically typed.
- moreice 4y agoAgreed, also consider C++ whose type system uses implicit conversions and mutability by default, leading to a number of non-memory related bugs.
- andrewxdiamond 4y ago> The unique safety features of Rus are all about memory safety, which is not something you have to worry about at all in Python Rust gets safety with its ownership system. The ownership system brings strong guarantees around who is mutating / reading any given object. Python has uncontrolled ownership. Any function can generally mutate / store any variable you pass in. This can definitely cause bugs if a rouge function starts modifying input. Rust makes this impossible without the mutation “permission” being part of the method signature. Strong ownership controls force functions to be extremely explicit with their intentions
- rustinquisition 4y ago
- deleted 4y ago[deleted]
- Too 4y agoFor those not familiar with ownership concepts, it does apply to many things beyond just memory management. Most obvious example of this is file handles. In python you have to close() them or scope within a context manager to auto close when the block exits. If you need more complex logic around, such as transfer the handle into another function, the context manager is no longer sufficient and you quickly loose track of who should call close(), is it the caller or the callee. Rust keeps track of this, no matter how deep you twist your logic and it does so for every variable, no context manager blocks required.
- cztomsik 4y agowrong, rust is about exclusive ptr access, nothing more. you cannot do ReadOnly<T> in rust.
- pg999w 4y agoWhy not? Isn't that &T like a read only wrapper of T?
- rustinquisition 4y ago
- manholio 4y agoRust has no exceptions and enforces correct propagation of errors at compile time. There are few if any strong typed languages in current use that offer a similar experience, for this mix of [memory safety + strong types + error correctness + close to machine performance] you would have to go to some very exotic language route. Unlike those exotic options, Rust also comes out of the box with a very powerful free linter (clippy) which you definitely want to use, and has a wide community, library, cargo ecosystem, is very stable and tested etc. When you total it up, you get a fast, safe program that exhibits 60-70% less runtime bugs than something written in either Python or C++ for a similar development effort. You still need to test of course, but you can focus on major integration and logic bugs instead.
- rowanG077 4y agoWhile the big one for rust borrowing system is memory bugs it als make it extremely specific what can be mutated. And there can only be a single mutator at any time. Unless you explicitly write something to work for multiple mutators. This makes many logic bugs much more obvious even though you could still make them. And of course you don't have nullability which is another big one.
- krab 4y agoDue to the pain that concurrency is in Python, the codebases I've seen mostly shared data only via external processes (queues, databases). I was very surprised to read the article. I think in the code I have in mind the borrow checker would only add overhead. The most frequent errors I see in the Python webapp code are: 1. logic errors, especially around concurrent DB transactions, 2. type errors (missing values, improperly modeled data), 3. performance problems.
- rowanG077 4y agoIt's not only threads. It's also explicit in whether a function can modify an argument because it's type signature says this with the mut keyword.
- krab 4y agoYou're right. It just doesn't seem to create much issues in the application code I have experience with.
- s17n 4y agoWell the article is about writing a database, which is definitely going to need concurrency and communication via shared memory to deliver the performance that it needs to (which is why the original implementation was mostly C++ and the new one is Rust). But yeah, I think in general if you're running into issues with mutability in Python, you're either using Python for something it should not be used for, or you're just programming in a really weird way.