Typed nils in Go 2
41–50 of 119 posts
Re: Typed nils in Go 2
#42Re: Typed nils in Go 2
#43Re: Typed nils in Go 2
#44Earlier quoted context omitted.
this is called a bottom type in a type system. In JVM languages null and the throw expression return the bottom type. The only other option is to not have nil values.
The problem is "null" being a value in all (non primitive) types, not only the bottom type. You specify "String", but you can have "null" too. When everything is optional, how do you specify that function foo really takes a String, not null? ( https://stackoverflow.com/questions/4963300/which-notnull-ja... )
Null is not a value of bottom type. Bottom type has no values.
Re: Typed nils in Go 2
#45Yet another item to add to my list-of-reasons-of-why-not-to-use-Go. Thanks
Honestly if you aren't a skilled enough programmer to navigate the nuances of any particular language then you really are no better than kids playing in drag-and-drop environments like Scratch.
Re: Typed nils in Go 2
#46Earlier quoted context omitted.
If you don't use languages because they have some edge cases and minor flaws how do you do any programming at all?
Does that sound like an edge case?
Re: Typed nils in Go 2
#47Yet another item to add to my list-of-reasons-of-why-not-to-use-Go. Thanks
If you don't use languages because they have some edge cases and minor flaws how do you do any programming at all?
Re: Typed nils in Go 2
#48Earlier quoted context omitted.
The problem is "null" being a value in all (non primitive) types, not only the bottom type. You specify "String", but you can have "null" too. When everything is optional, how do you specify that function foo really takes a String, not null? ( https://stackoverflow.com/questions/4963300/which-notnull-ja... )
> The problem is "null" being a value in all (non primitive) types, not only the bottom type. Null is not a value of bottom type. Bottom type has no values.
Re: Typed nils in Go 2
#49Re: Typed nils in Go 2
#50Earlier quoted context omitted.
Can someone point me to some examples where checking that the type of an interface is nil? I have thought a bit about it but I couldn't come up with good situations.
"the type of an interface is nil" is that even possible?
var a interface{} = nil // (nil, nil)
var b *int = nil
var c interface{} = b // (*int, nil)
fmt.Println(a == c)
Of course most such cases are not that trivial, rather they're cases where a function takes an interface-valued parameter and checks for (param == nil), if the caller passes in an actual object there's no problem, if they pass in a concrete value no problem, but if they extract the nil literal to a concretely-typed context (variable) things go pear-shaped to various levels of fuckedness (depending what is done in the other branch).And that's vicious because something as seemingly innocuous as "extract variable" on an immutable literal can break your code.