IsZero

105 views
Skip to first unread message

Helton Marques

unread,
Jul 20, 2017, 4:10:15 PM7/20/17
to golang-nuts
There's some reason to not have the function `IsZero` to time.Duration ?

IMO, I think this can be useful: 


```
type Server struct { timeout time.Duration `yaml:"timeout:"` }
...
if srv.timeout.IsZero() { srv.timeout = defaultServerTimeout } 
```

Anyone knows if there's some restriction to not have IsZero() bool functions to defined types as int64 ?

Regards,

Ian Lance Taylor

unread,
Jul 20, 2017, 4:12:04 PM7/20/17
to Helton Marques, golang-nuts
Where you want to write `d.IsZero()`, you can just write `d == 0`.
I'm not sure adding a `IsZero` method is really worth it.

Ian

Helton Marques

unread,
Jul 20, 2017, 5:51:00 PM7/20/17
to golang-nuts, helto...@gmail.com
Yeah, I now, but considering these proposal: https://github.com/golang/go/issues/20757 
This function (IsZero) would not bring even more reliable use ?

Ian Lance Taylor

unread,
Jul 20, 2017, 6:24:07 PM7/20/17
to Helton Marques, golang-nuts
On Thu, Jul 20, 2017 at 2:50 PM, Helton Marques <helto...@gmail.com> wrote:
>
> Yeah, I now, but considering these proposal:
> https://github.com/golang/go/issues/20757
> This function (IsZero) would not bring even more reliable use ?

Sure, if we adopt proposal #20757 we may well need or at least want an
IsZero method. That is a Go 2 proposal, though; for Go 1 I don't see
sufficient benefit.

Ian
Reply all
Reply to author
Forward
0 new messages