I thought of this at the beginning, but when I tried to make it work I realized that I needed to have the following if: if s != nil { /* initialize struct or inform it is nil */ }
on every struct method, which eventually defeated the purpose for my use case. Out of curiosity: Could you please tell when calling methods on nil pointers is useful? El sábado, 15 de febrero de 2020, 13:51:32 (UTC), Tristan Colgate escribió: > > It's also worth pointing out that a nil pointer value can still be useful. > You can still call methods on it. > > On Sat, 15 Feb 2020, 13:13 , <klos...@gmail.com <javascript:>> wrote: > >> Woah! that's a killer reason, the one I was searching for. Thanks for >> pointing it out, as you have saved me a lot of time discarding the proposal >> I had in mind. >> >> I will need to go in other direction. >> >> El viernes, 14 de febrero de 2020, 15:52:07 (UTC), Brian Candler escribió: >>> >>> In addition, consider: how would you implement the zero default when >>> the type is self-referential? For example: >>> >>> type Treenode struct { >>> left *Treenode >>> right *Treenode >>> } >>> >>> var Tree1, Tree2 *Treenode >>> >>> Also consider deeply nested types which include pointers to structs >>> which contain pointers etc. >>> >>> You can design a language where pointers can never be nil - but then you >>> have to deal with "does not point to anything" some other way (e.g. Maybe >>> values). That ends up with a very different language. >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golan...@googlegroups.com <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/e2969605-f82f-4b38-a390-87539c9f3041%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/e2969605-f82f-4b38-a390-87539c9f3041%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/584430ea-016a-418f-ac6b-c37cd5daee0b%40googlegroups.com.