Hacker News new | past | comments | ask | show | jobs | submit login

> Though I don't really see how "int*" is different from "Optional<int>".

One requires you to handle the possibly-nil case in order to access the pointer, the other expects you to remember to check every time.

The following is completely legal, and results in a runtime error:

    func foo(maybeInt *int) {
      x := *maybeInt // runtime panic
    }
The following is not, and results in a compile-time error:

    func foo(maybeInt Optional<int>) {
       x := *maybeInt // compile error: need to unwrap maybeInt
    }



Annoying that the various Go linters I have installed (`go vet`, `golangci-lint`, `gosec`) don't catch "possible use of pointer before nil-check" - you'd think it would be an obvious case for those to handle.


That would be very annoying to use as many pointers are just assumed to be non-nil and you don't have any other option but to assume they're non-nil.

Also since Go supports nil receivers, it would have to require that every "pointer method" be checked for nil. Which technically they should, but...


I'd imagine it'd be one of the "disabled by default" in `golangci-lint`, for example - helpful for when you're doing an in-depth review of the code but probably not something you want running on every CI invocation.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: