-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logs refactor - migrating to zap #281
Conversation
type msec time.Duration | ||
|
||
func (f msec) String() string { | ||
ms := time.Duration(f) / time.Millisecond |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Code Quality Violation
do not use a time prefix for duration variables (...read more)
In Go, the time.Duration
type represents a duration of time. It is an integer or float type that represents the length of a duration in units such as seconds, milliseconds, or nanoseconds.
When working with time.Duration
variables in Go, it is important to note that the type itself already represents a duration with a specific unit. The unit of the duration is determined by the context in which it is used. Therefore, it is not necessary to explicitly include the unit in the variable name or identifier.
Here are a few reasons why we should avoid using time units in variable names for Go's time.Duration
type:
- Clarity and readability: By not including time units in the variable name, the code becomes more concise, clear, and easier to read. This is because the
time.Duration
type already implies that the value represents a duration. - Flexibility and reusability: By not tying the variable to a specific unit, it becomes more flexible and reusable. For example, if a variable is named
retryTimeout
instead ofretryTimeoutSeconds
, it can be easily changed to represent a different unit (e.g., milliseconds) without affecting the variable name. - Consistency with standard library: Go's standard library, including the
time
package, follows the convention of using the type name (Duration
) without including time units in variable names. By following this convention, our code aligns better with the standard library and promotes code consistency.
To ensure good coding practices, it is recommended to name Go time.Duration
variables in a descriptive and context-specific manner without explicitly mentioning the time unit in the variable name. This approach leads to clear and maintainable code.
…und into jt-dd/logs-refactor
No description provided.