Why this matters
Using dedicated time types makes the code self-documenting and less error-prone. It prevents confusion over units (seconds vs milliseconds) and provides helpful methods. This leads to clearer and more correct time calculations.
Use the time package's types for handling time. For example, represent instants as `time.Time` and durations or time intervals as `time.Duration` instead of raw numeric types (int, int64).
Using dedicated time types makes the code self-documenting and less error-prone. It prevents confusion over units (seconds vs milliseconds) and provides helpful methods. This leads to clearer and more correct time calculations.
Side-by-side examples engineers can pattern-match during review.
func ScheduleEvent(name string, ts int64) {
// 'ts' is a timestamp in seconds since epoch? milliseconds? unclear
// ...
}
timeout := 5000 // represents 5000 milliseconds? Or microseconds?
time.Sleep(time.Duration(timeout)) // bug: might sleep 5 microseconds if misinterpretedfunc ScheduleEvent(name string, t time.Time) {
// 't' clearly represents a moment in time
// ...
}
timeout := 5 * time.Second
time.Sleep(timeout) // clear 5 second timeoutfunc ScheduleEvent(name string, ts int64) {
// 'ts' is a timestamp in seconds since epoch? milliseconds? unclear
// ...
}
timeout := 5000 // represents 5000 milliseconds? Or microseconds?
time.Sleep(time.Duration(timeout)) // bug: might sleep 5 microseconds if misinterpretedfunc ScheduleEvent(name string, t time.Time) {
// 't' clearly represents a moment in time
// ...
}
timeout := 5 * time.Second
time.Sleep(timeout) // clear 5 second timeoutFrom the same buckets as this rule.
All static JS/CSS/font/image files MUST use content-hashed filenames (e.g., app.9c1a7b.js) and be served with "Cache-Control: public, max-age=31536000, immutable". HTML and other non-fingerprinted documents MUST be served with "Cache-Control: no-cache" (or equivalent) to enable conditional revalidation.