Remix.run Logo
flowerthoughts 5 hours ago

In this case, the missing piece in Go is the NonNullable hint. That would make it clear that null checks aren't needed, enforceable by the type system, and lintable.

Option types just forces you to do the check, but doesn't remove the need for it.

Now that we have generic types, a NonNullable intrinsic type seems doable...

ThePhysicist 3 hours ago | parent | next [-]

It's quite easy to write a generic Maybe struct that performs most of the encapsulation that Rust's Maybe does i.e. allow unwrapping of the inner type through a function or handling the nil case through a switch like statement. I've never seen this in the wild which makes me think people don't care about it too much. And of course it's runtime based so no compile time guarantees, and just to preempt the expected replies I know it's not the same what Rust is capable off and Rust is of course a much much much much better language than Go.

Personally I do experiment with these things as it makes code more readable, it just seems adoption for generics and what you can do with them is still quite low in the broader community. That said I do not deal with null pointer exceptions much at all, and when I do it's often relatively simply to spot and fix, so for me it's not a large issue.

cubefox 5 hours ago | parent | prev | next [-]

Or a set theoretic type system with union type declarations (foo|null), like in TypeScript.

sail0rm00n 5 hours ago | parent | prev [-]

References like C++, maybe?