Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

.IsZero() is a pragmatic solution given the constraints of the system (i.e. Go language).

Go has a notion of "zero value". When you don't assign a value explicitly it'll be set by the compiler to "zero value" of that type.

This is much better than C/C++ of "random value".

For primitive types, the compiler decides what "zero value" is. For structs, each component is set to its zero value.

For good reasons (language simplicity) Go doesn't allow the user to declare what the zero value is (something that you can do in e.g. C++ via a constructor).

Time is a struct. Its zero value is the same as for any other struct and not meaningful time value.

It's a pragmatic necessity to be able to query "is this time value an unset time value?". A pragmatic solution for this need is to provide IsZero() method on Time struct.



It may be pragmatic, but it’s incorrect. “Is this time value an unset time value?” is not a question you can answer (using IsZero considers the epoch an unset time value, but it’s a perfectly valid set one too).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: