4 ms·
You can use var now = time.Now
by Jabbles 10y ago
You can use
var now = time.Now
- dilap 10y agotrue, tho slight savings in characters not worth the less-clear definition imo
- skj 10y agoIs that really less clear?
- dilap 10y agoI think so -- if I see this it's obvious now is a function. func now() time.Time { return time.Now() } If I see this: var now = time.Time My first instinct is, "hmmm, some kind of variable?" And then I have to remember, "oh yeah, it's just a variable that holds a function." Obviously not a big deal either way. (I think this further shows how type aliases would not be adding much possibility for confusion compared to what already exists in the language.)
- ithkuil 10y agobtw if you want you can explicit mention the type in the var declaration
- randomdata 10y agoOn the other hand, you may want to set `now` to return a deterministic time value when testing, which the variable allows.