Hacker News new | ask | show | jobs
by 38 562 days ago
> The worst example is pointers since they're used to represent both references and optional values.

using a pointer as an optional value is an anti-pattern. correct idiom is to return a tuple:

    type positive struct{}
    
    func new_positive(i int) (*positive, bool) {
       if i >= 0 {
          return positive{}, true
       }
       return nil, false
    }