-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Bloomfilter: parameter variables made constant #9750
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
Conversation
utACK 64aa36e |
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.
utACK
Why would you make non-reference and non-pointer variables const? Please first add this and the rationale to doc/developer-notes.md. I don't see a point of doing this out of the blue, sorry. |
I find it useful when reading code if anything that can be const'd is const'd. to quote S.O.:
http://stackoverflow.com/questions/8714250/isnt-const-redundant-when-passing-by-value There is no harm to making this change, and at best, there is the gain that the above sorts of bug won't later be introduced. Also, in theory such an annotation could help the optimizer better inline such a function. |
I agree. However we don't follow everything that is "generally considered good style" by random people on the internet in this project. We most notably don't do this structurally anywhere else, so why start in the bloom filter code specifically? If you want to introduce this rule, that's fine, I have no reason to be against it, but that needs to be discussed first in a PR adding that recommendation to the developer guide, then merged. Then you can start changing existing code to do that. |
Thanks for the discussion. It's true that this standard isn't enforced anywhere else, so i can see how it seems out of the blue. A recent project of mine used bloom filters and so I was interested to check out bitcoin's filter and thought it wouldn't hurt to apply some of the standards i used which I thought were helpful. I agree, it is kind of random so I'll look more into if I can find a more reasonable argument for the change and then make an attempt on the developer notes. |
I agree that making things const that can be made const is a good idea, taking the virality property as mentioned in Google's C++ styleguide (Use of const) into appropriate consideration. I also agree that the developer guidelines should include this direction. |
One thing I don't like about making by-value parameters const is that something that is private and internal to the function - how their copy of the parameter is handled - needs to be specified on the interface, even though it makes no difference to the ABI. That's a minor problem though and if it's done consistently everywhere I have no problem with it. Edit: something else that we need to be clarify in the coding style is the use of "override". E.g. I had to add a few in #9764 to prevent gcc from complaining: it doesn't like when it's used inconsistently within a class. |
I didn't even know "override" existed. As for how parameters are handled, I'm of the opinion that function/method parameters should never be changed ever, unless they are explicitly marked as "output parameters", even for primitive types like ints and such, where it doesn't matter. The primary reason is that it's much easier to read code where the input parameters always stay the same no matter what. I even prefer the following void foo(const int inX) {
int x = inX ?: computeStartingX();
// ...
} over void foo(int x) {
if (!x) x = computeStartingX();
// ...
} which is one of the few "ugly" cases with this approach. |
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
Summary: 64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd Backport of Core PR9750 bitcoin/bitcoin#9750 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, markblundeberg, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3406
Summary: 64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd Backport of Core PR9750 bitcoin/bitcoin#9750 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, markblundeberg, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3406
Summary: 64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd Backport of Core PR9750 bitcoin/bitcoin#9750 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, markblundeberg, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3406
Summary: 64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd Backport of Core PR9750 bitcoin/bitcoin#9750 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, markblundeberg, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3406
Summary: 64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd Backport of Core PR9750 bitcoin/bitcoin#9750 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, markblundeberg, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3406
Summary: 64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd Backport of Core PR9750 bitcoin/bitcoin#9750 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, markblundeberg, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3406
Summary: 64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd Backport of Core PR9750 bitcoin/bitcoin#9750 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, markblundeberg, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3406
64aa36e param variables made const (ロハン ダル) Tree-SHA512: 7c19f9e7dd574c8ce8a9468555f27196735b583efe349c1309c90e1e5d2949daf6891574b4bea7122d6c6aca0c7ee4a782fe3d24918d889f7bf89227084a51cd
Backport bloom filter improvements Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#7113 - bitcoin/bitcoin#7818 - Only the second commit (to resolve conflicts). - bitcoin/bitcoin#7934 - bitcoin/bitcoin#8655 - Partial backport to help resolve conflicts. - bitcoin/bitcoin#9060 - bitcoin/bitcoin#9223 - bitcoin/bitcoin#9644 - Partial backport to help resolve conflicts. - bitcoin/bitcoin#9916 - bitcoin/bitcoin#9750 - bitcoin/bitcoin#13176 - bitcoin/bitcoin#13948 - bitcoin/bitcoin#16073 - bitcoin/bitcoin#18670 - bitcoin/bitcoin#18806 - Reveals upstream's covert fix for CVE-2013-5700. - bitcoin/bitcoin#19968
Backport bloom filter improvements Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#7113 - bitcoin/bitcoin#7818 - Only the second commit (to resolve conflicts). - bitcoin/bitcoin#7934 - bitcoin/bitcoin#8655 - Partial backport to help resolve conflicts. - bitcoin/bitcoin#9060 - bitcoin/bitcoin#9223 - bitcoin/bitcoin#9644 - Partial backport to help resolve conflicts. - bitcoin/bitcoin#9916 - bitcoin/bitcoin#9750 - bitcoin/bitcoin#13176 - bitcoin/bitcoin#13948 - bitcoin/bitcoin#16073 - bitcoin/bitcoin#18670 - bitcoin/bitcoin#18806 - Reveals upstream's covert fix for CVE-2013-5700. - bitcoin/bitcoin#19968
Just a suggestion, since I see none of the variables I've transformed into constants are altered in their respective methods. If changes want to implemented later on so they can be altered, it would be an easy fix but I feel the code is cleaner this way.
let me know your thoughts!