News for hackers. Stuff that matters.
Re:Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers by TylerE on Sunday September 04, 2016 @09:31PM (#12427594)
What's wrong with using an Option/Maybe type? Can't Go do that?
Re:Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers by cyphar on Sunday September 04, 2016 @09:45PM (#12427627)
You could (just use an interface). However, it would be a pain to use because Go doesn't have generics (if a type X implements the Maybe interface, it is not true that []X can be casted to []Maybe). So you would have to always make temporary slices to copy all of your Xs into.
Re:Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers by brobinson on Sunday September 04, 2016 @09:56PM (#12427660)
Go effectively has Option types for database query results: https://golang.org/pkg/database/sql/#NullBool
Re:Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers by unscaled on Sunday September 04, 2016 @10:15PM (#12427724)
This is not a generic option type, but rather a tri-state bool, or an Option<bool>. Go has no user-defined generics, so you can't have a bool type. It does have built-in "magical" generics, namely arrays, slices maps and channels, but no option/maybes. Language-level option types are not unheard of (C#, Swift and Kotlin all have a notion of this sort, although they all support proper user-defined generics as well).
Re:Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers by masklinn on Monday September 05, 2016 @05:54AM (#12429211)
> Language-level option types are not unheard of (C#, Swift and Kotlin all have a notion of this sort)

Swift's Optional is a library type: https://github.com/apple/swift/blob/master/stdlib/public/cor...

Though the compiler is aware of it and it does have language-level support (nil, !, ?, if let)