News for hackers. Stuff that matters.
Re:Go nulls and SQL by worik on Monday May 23, 2022 @04:14PM (#31484275)
You cannot use a null pointer in Rust.

I am a Rust novice but I have not found a way to get to uninitialised memory in safe Rust. Yet.

Re:Go nulls and SQL by imron on Monday May 23, 2022 @09:50PM (#31487149)
> You cannot use a null pointer in Rust.

Yes you can: https://doc.rust-lang.org/std/ptr/fn.null.html

You just won't use it unless you're doing FFI or similar things.

Re:Go nulls and SQL by worik on Tuesday May 24, 2022 @03:18PM (#31496377)
FFI is unsafe, by definition.
Re:Go nulls and SQL by imron on Tuesday May 24, 2022 @07:19PM (#31498696)
You can still use null pointers in safe rust (see the link I posted which is 100% safe rust), you just can’t deference then.
Re:Go nulls and SQL by worik on Tuesday May 24, 2022 @09:18PM (#31499538)
Ok.

I meant "using null pointer" means dereference it. But careless language....

Re:Go nulls and SQL by tedunangst on Monday May 23, 2022 @04:20PM (#31484335)
How do you create a pointer to uninitialized memory in go?
Re:Go nulls and SQL by TheDong on Monday May 23, 2022 @05:52PM (#31485231)
All it takes is a specially formatted comment

    /*
    int g() {
     volatile int x;
     return x;
    }
    */
    import "C"

    import "fmt"

    func main() {
     fmt.Printf("%d\n", C.g())
    }

But I know you'll say that 'import "C"' or 'import "unsafe"' is the same thing as using an unsafe block in rust or such, and really shouldn't count against go.

Which is fair and true, but you're chasing down a pointless detail. The point isn't that go is memory unsafe. It's not. The point is that Go's type-system is not powerful enough to express various types of type-safety, and as such it's an error-prone language where you can expect null pointer exceptions frequently.

Re:Go nulls and SQL by Gwypaas on Monday May 23, 2022 @04:45PM (#31484574)
You can't. But a runtime panic also very easily causes an outage. At least it's not as subtle.

Still. Rust is infinitely better in this regard. Go feels like a crude hammer, especially regarding the default interaction between deserialization and missing struct members.

Re:Go nulls and SQL by stouset on Monday May 23, 2022 @05:52PM (#31485232)
You can't. But you can absolutely have a `nil` that will unavoiad runtime panics if you don't check it. And further, you only can't do this because go defines by fiat that the zero-value of a type must be legal. Of course, this is wildly inconvenient and annoying for many types, including those that come bundled in the standard library.

There are other, very convincingly better options to this that many in this thread have been trying to teach you about in the expectation that your responses have been in good faith.