I don't understand this comparison. The C idiom you mention is concretely
typed (i.e. C doesn't have interfaces, so it doesn't have dynamic types),
so I fail to see what it has to do with interfaces. And it makes *far* more
sense to check if you got passed a nil-pointer, than to check the concrete
value of an interface -- i.e. something like this makes of course *some*
sense, in Go:

func Foo(p *string) {
    if p != nil {
        *p = doSomeStuff()
    }
}

It makes sense to check p for nil, because you know its type and you know
you can't use it, if its nil. It's thus a very different problem than what
this thread is about.

Moreover, how does, what you say what was said above? i.e. a) As a user of
an interface, its dynamic value shouldn't concern you, in general, b) not
all zero values are nil, so checking for nil to see whether the dynamic
value is the zero value doesn't make sense and c) the zero value -
including nil - is a perfectly valid implementation of an interface?



On Tue, Jan 2, 2018 at 1:40 AM, David Collier-Brown <dav...@spamcop.net>
wrote:

> Drifting back toward the original subject, I'm reminded of the non-bsd-c
> idiom of
>
> char *foo(char *p) {
>     if (p != NULL && *p != NULL) {
>         return some string operation...
>     }
> ...
>
> It seems logical to check the type of the contents of an interface
> type, and its presence in a function that can take nil types and
> nil contents, much as in the C idiom.
>
> Mind you, I do find type assertions a bit clunky.
>
> --dave
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to