cristaloleg/go-advice

Explanation on a point

agnivade opened this issue · 4 comments

use time.Before and time.After to compare time, avoid time.Sub

What is the reason behind this ?

Just to make it clear.
When I see time.Sub at first I think: what you will do with a difference later?
But in most cases it's used only for comparison.
Using time.Before or time.After it makes much clear from the begging, less distractions during code review, refactoring and slightly error prone.

Oh I must have misunderstood. I could not imagine that people use time.Sub to compare. Do they check if the duration is greater than 0 ?

Anyways, I think the description can be worded better to indicate that it's a code improvement. Just by reading the line, it sounded that there is some performance reason behind it.

Yeah, they use 😉
Can you make a PR with an explanation?

Sure.