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

NoNewGlobals for SBufStats #1754

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yadij
Copy link
Contributor

@yadij yadij commented Mar 23, 2024

Issues found by Coverity scan CID 1554550, 1554554, 1554574,
1554597, 1554604, 1554605, 1554613, 1554626, 1554602.

@rousskov rousskov self-requested a review March 24, 2024 00:23
Comment on lines +27 to +30
SBufStats &
SBuf::Stats()
{
static auto *stats = new SBufStats;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please apply NoNewGlobals code pattern rather than using a similar but different one:

Suggested change
SBufStats &
SBuf::Stats()
{
static auto *stats = new SBufStats;
auto &
SBuf::Stats()
{
static const auto stats = new SBufStats();

N.B. The same applies to virtually any methods in other PRs that can use that pattern. Reusing that pattern helps improve code quality and reduce review iterations/delays.

@@ -339,7 +339,7 @@ class SBuf
SBuf consume(size_type n = npos);

/// gets global statistic information
static const SBufStats& GetStats();
static const SBufStats & GetStats() { return Stats(); }
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not have two class methods named GetStats() and Stats(). The names should tell the two methods apart. This was discussed four days ago in another very similar PR: #1749 (comment). Let's reuse the same approach here:

  • Use WriteableStats() name for the new method.
  • Use GetStats() to preserve old method callers and use a simpler name for the safer method. This method should have been named Stats(), but we do not need to improve that in this PR.
Suggested change
static const SBufStats & GetStats() { return Stats(); }
static const auto &GetStats() { return WriteableStats(); }

If you prefer to also rename GetStats() to Stats() in this PR, I will support that change as well, but I do not insist on it. Your call.

Copy link
Contributor Author

@yadij yadij Mar 25, 2024

Choose a reason for hiding this comment

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

IIRC the GetStats() only exists because you insisted on the single caller (mgr dump function) being provided a const. Statistics objects are generally always writable in Squid so they can be updated by the caller/user code, so calling it WritableStats is redundant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alex: We should not have two class methods named GetStats() and Stats(). The names should tell the two methods apart. This was discussed four days ago in another very similar PR: #1749 (comment). Let's reuse the same approach here

Amos: IIRC the GetStats() only exists because you insisted on the single caller (mgr dump function) being provided a const. Statistics objects are generally always writable in Squid so they can be updated by the caller/user code, so calling it WritableStats is redundant.

The response quoted above clearly does not address my concern about PR code/changes.

I do not see "redundancy" in "[Get]Stats() and WriteableStats()" naming scheme. If you reject the proposed solution (mimicking the one developed in #1749), please propose something better than that solution. Hopefully, both PRs (and future PRs!) can use the same overall approach that we can agree on.

@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Mar 25, 2024
@squid-anubis squid-anubis added M-failed-other https://github.com/measurement-factory/anubis#pull-request-labels and removed M-failed-other https://github.com/measurement-factory/anubis#pull-request-labels labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-for-author author action is expected (and usually required)
Projects
None yet
3 participants