Skip to content
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

Merged
merged 28 commits into from
Oct 18, 2024
Merged

Logs refactor - migrating to zap #281

merged 28 commits into from
Oct 18, 2024

Conversation

jt-dd
Copy link
Contributor

@jt-dd jt-dd commented Oct 15, 2024

No description provided.

type msec time.Duration

func (f msec) String() string {
ms := time.Duration(f) / time.Millisecond

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:

  1. 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.
  2. 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 of retryTimeoutSeconds, it can be easily changed to represent a different unit (e.g., milliseconds) without affecting the variable name.
  3. 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.

View in Datadog  Leave us feedback  Documentation

@jt-dd jt-dd marked this pull request as ready for review October 18, 2024 16:00
@jt-dd jt-dd requested a review from a team as a code owner October 18, 2024 16:00
@jt-dd jt-dd merged commit c76e63f into main Oct 18, 2024
8 checks passed
@jt-dd jt-dd deleted the jt-dd/logs-refactor branch October 18, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants