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

Backport (1.x): Add limits to #log_deprecation #3780

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

delner
Copy link
Contributor

@delner delner commented Jul 11, 2024

What does this PR do?

Backports #3675 to 1.x-stable. I intend to rebase #3647 on top of it to leverage the limit feature.

@delner delner added core Involves Datadog core libraries feature Involves a product feature labels Jul 11, 2024
@delner delner added this to the 1.23.4 milestone Jul 11, 2024
@delner delner self-assigned this Jul 11, 2024
@delner delner requested a review from a team as a code owner July 11, 2024 18:19

Datadog.logger.warn do
message = yield
message += ' This will be enforced in the next major release.' if disallowed_next_major

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static Analysis Violation (ruby-best-practices/concat-strings)

⚪ Notice - Best Practices - View in Datadog

Suggested change
message += ' This will be enforced in the next major release.' if disallowed_next_major
message << ' This will be enforced in the next major release.' if disallowed_next_major
Avoid appending to string using += (read more)

The rule to avoid slow string concatenation in Ruby is essential for writing efficient and fast-performing code. String concatenation using the += operator is slower because it creates a new string object every time it's used. This can lead to performance issues, especially in loops or large programs where numerous string concatenations might be happening.

Instead, the << operator, also known as the append operator, should be used for string concatenation in Ruby. The << operator modifies the original string, avoiding the creation of multiple unnecessary string objects. This results in faster execution time and lower memory usage, which is especially beneficial in larger applications or systems with limited resources.

Therefore, good coding practice in Ruby suggests using << for string concatenation instead of +=. For instance, output << "<p>#{text}</p>" is more efficient than output += "<p>#{text}</p>". Following this rule will help you write cleaner, faster, and more resource-efficient Ruby code.

Leave feedback in #static-analysis

@delner delner merged commit 63f8b18 into 1.x-stable Jul 11, 2024
192 of 193 checks passed
@delner delner deleted the backport/1.x/add_log_deprecation_limits branch July 11, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries feature Involves a product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants