When I run this code: var ( aslice []string amap map[int]string afunc func() ) fmt.Println("aslice is:", aslice) fmt.Println("amap is:", amap) fmt.Println("afunc is:", afunc) it displays: aslice is: [] amap is: map[] afunc is: Therefore, why at 7:03 you say the zero value for slices and maps is nil? They looks to be empty slice and empty map !! I did expected to be displayed as for 'afunc' variable. By the way, when I added this code: if aslice == nil { fmt.Println("aslice is nil") } It has printed 'aslice is nil' :), therefore they are nil as in language specification but I suppose Println is confusing me. Maybe because we have different 'types' of nil in Go. I guess I have to watch the presentation again :).
Actually I just figured it out - he's saying "ALGOL". He specifically mentioned that he invented null in 1965, which matches this: en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions
It would be better if we could "opt out" of nil for specific types, especially maps, where we don't want it. Same for non nillable types so we could "opt in"
17:35 "You're not using the pointer. You're not dereferencing it. It will just work. [...] This is different to C++". Actually, C++ allows this. If you don't dereference the nullptr, nothing bad will happen. You can call a member function on the nullptr and it will just work.
I'm don't use C++, so if this is the scenario you're talking about that C++ allows, apologies, but what he's saying there is sayHi() is a method on type person. If you have a pointer to a person, we'll call frank, and that pointer is nil you can still call sayHi() and it will work play.golang.org/p/RtmcKuuzlUS
Your assumption is completely wrong, may work in debug build subjected you are not accessing any member variables of that class. In general, it will always lead to a crash.
@@anilkumar8753 How could it always lead to a crash? It will crash if you're accessing a member variable. It will crash if you're calling a virtual function. If you're doing neither of those things then I don't see how it could crash. It is technically undefined behaviour in any case but practically speaking, I don't see how it could be unsafe. I tried this example godbolt.org/z/fv9cqM on various compilers and optimization levels and wasn't able to make it crash.
Actually calling method is considered pointer dereference in C++, so the behaviour is undefined. If the behaviour is undefined, it may crash the program, it may not, but the language still forbids it and the program is ill-formed.
You only realize how stupid GoLang nil is when you work with a null-safe language like dart. What a dumpster fire GoLang is with all the creative ways your app can crash unexpectedly or hang in tight loops unexpectedly. If only one could have language with such a fast compiler as go, and such great runtime performance,but with checked nil safety, then it could have been really amazing. Instead these geniuses decided to design the language to be full to the brim with foot-guns while bragging how simple and easy to learn the language is.
Thank you Francesc Campoy. You teach me a lot.
I've been programming in Go for a couple of years, but this clarified my understand of nil. Thanks.
Thank you for dark theme.
different nils, "nil slice" is just a "nil slice" which is different to "nil pointer" which is different to "nil interface"...
2020 and still super informative
I agree in 2023.
Wow, this was an incredibly informative talk. Thanks very much for this!!
When I run this code:
var (
aslice []string
amap map[int]string
afunc func()
)
fmt.Println("aslice is:", aslice)
fmt.Println("amap is:", amap)
fmt.Println("afunc is:", afunc)
it displays:
aslice is: []
amap is: map[]
afunc is:
Therefore, why at 7:03 you say the zero value for slices and maps is nil? They looks to be empty slice and empty map !! I did expected to be displayed as for 'afunc' variable.
By the way, when I added this code:
if aslice == nil {
fmt.Println("aslice is nil")
}
It has printed 'aslice is nil' :), therefore they are nil as in language specification but I suppose Println is confusing me. Maybe because we have different 'types' of nil in Go.
I guess I have to watch the presentation again :).
every type can print their nil value in a different way, you can try it yourself
play.golang.org/p/lxh_gqJ9as
OK, it depends how each type implements Stringer interface. Thanks.
It's not the types that implement Stringer (built-ins have no methods). Rather that's how the fmt package prints them.
where can I find the slice thx
how do one, register to talk at Gopher Academy
I assume that when the speaker says "Occal" (at least that's what it sounded like) he meant to say the "Occam" language, right?
Oh. I didn't know there was a connection between Tony Hoare and OCaml, interesting.
Actually I just figured it out - he's saying "ALGOL". He specifically mentioned that he invented null in 1965, which matches this: en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions
Is there any recording of the "Functional Go, Thanks, but No" available?
th-cam.com/video/ouyHp2nJl0I/w-d-xo.html
th-cam.com/video/ouyHp2nJl0I/w-d-xo.html
It would be better if we could "opt out" of nil for specific types, especially maps, where we don't want it. Same for non nillable types so we could "opt in"
what is doError in th-cam.com/video/ynoY2xz-F8s/w-d-xo.html ?
It implements the error interface.
That is just a dummy implementation for error{} interface merely to explain the interface {*something, nil} != nil concept.
17:35 "You're not using the pointer. You're not dereferencing it. It will just work. [...] This is different to C++". Actually, C++ allows this. If you don't dereference the nullptr, nothing bad will happen. You can call a member function on the nullptr and it will just work.
I'm don't use C++, so if this is the scenario you're talking about that C++ allows, apologies, but what he's saying there is sayHi() is a method on type person. If you have a pointer to a person, we'll call frank, and that pointer is nil you can still call sayHi() and it will work play.golang.org/p/RtmcKuuzlUS
Ryan Swanson That's what I'm saying. It works in Go and it works in C++. cpp.sh/9kyq5
Your assumption is completely wrong, may work in debug build subjected you are not accessing any member variables of that class. In general, it will always lead to a crash.
@@anilkumar8753 How could it always lead to a crash? It will crash if you're accessing a member variable. It will crash if you're calling a virtual function. If you're doing neither of those things then I don't see how it could crash. It is technically undefined behaviour in any case but practically speaking, I don't see how it could be unsafe. I tried this example godbolt.org/z/fv9cqM on various compilers and optimization levels and wasn't able to make it crash.
Actually calling method is considered pointer dereference in C++, so the behaviour is undefined. If the behaviour is undefined, it may crash the program, it may not, but the language still forbids it and the program is ill-formed.
Jesus christ, already 4 years ago people putting a gender disclaimer in their talks?
You implemented Maybe in a language that doesn't support typing rich abstractions, hence it was bad.
// to watch
You only realize how stupid GoLang nil is when you work with a null-safe language like dart. What a dumpster fire GoLang is with all the creative ways your app can crash unexpectedly or hang in tight loops unexpectedly. If only one could have language with such a fast compiler as go, and such great runtime performance,but with checked nil safety, then it could have been really amazing. Instead these geniuses decided to design the language to be full to the brim with foot-guns while bragging how simple and easy to learn the language is.
Then you realize how stupid is Dart's inability to cross compile to a single binary.
@@jeffreysmith9837 wait wtf, how can you cross compile to a single binary?? don't think even go can do that!!