3 ms·
I mean, it's opt-in. If you really want to crap your pants, in today's Go, you can import C and call malloc and free, then import unsafe and make pointers into
by jchw 4y ago
I mean, it's opt-in. If you really want to crap your pants, in today's Go, you can import C and call malloc and free, then import unsafe and make pointers into the void. The point of memory safe programming languages is NOT that they entirely disallow all unsafe operations, it's that the language has a proper model for memory safety. In Rust, unsafe code needs to be in unsafe blocks. In Go, unsafe code is only possible by importing unsafe or C.
Adding more unsafe tools to Go or Rust do not diminish their safety guarantees. In fact, when Go and Rust add new unsafe features, they generally do so in a fashion that is much more constrained and has better defined edges than traditional methods, so that it's easier to use them correctly and easier to detect misuses. For example, the borrow checker still runs in Rust unsafe blocks; you still have to circumvent the borrow checker even once you're in unsafe. As for this arena package, it seems to have a few safety mechanisms, and hell, I don't even think it's off the table that it could be made entirely memory safe. This is especially true since memory safe does not mean "free of runtime errors", so all that is needed is to be able to detect the error conditions without allowing potentially undefined behavior to occur first.
Programming language experiments like Go's new arena package are good; they allow exploring what you can do to improve old concepts.
- heywhatupboys 4y ago> In Go, unsafe code is only possible by importing unsafe or C. of course, this is completely wrong, for anyone reading this. that is simply not how systems work
- the-smug-one 4y agoOK, do you intend to say why?
- thiht 4y agoHow do "systems" (whatever you're talking about) work then?
- mikedelago 4y agoI think they are speaking without the context that "unsafe = lack of memory safety" and with the context that "unsafe = you can still drop the database"
- jchw 4y agoNote that "unsafe" in this context refers to memory safety. I am not making the claim that Go code which does not import unsafe or C is free of bugs; however, if you don't import unsafe or C anywhere in your application or dependencies (sans the stdlib) then it is memory safe (assuming no compiler or OS bugs compromise that guarantee.) That's just how Go is specified. The unsafe package in Go provides unsafe.Pointer, which allows you to convert between a pointer and integral type, essentially allowing you to make pointers of any type to any address, giving up type safety. Without it, Go pointers are safe, because the GC will never free memory that has live pointers, and you can't do math on Go pointers.