Removes the example because it violates the code format.
doc: Tidy up shadowing section #16461
pull promag wants to merge 1 commits into bitcoin:master from promag:2019-07-fix-devnotes changing 1 files +2 −16-
promag commented at 3:48 PM on July 25, 2019: member
-
in doc/developer-notes.md:632 in 5bc447b924 outdated
633 | + Mode mode; 634 | + int index; 635 | + 636 | + AddressBookPage(Mode _mode, int _index) 637 | + : mode(_mode) 638 | + , index(_index)
promag commented at 3:49 PM on July 25, 2019:@MarcoFalke :trollface:
in doc/developer-notes.md:625 in 5bc447b924 outdated
621 | @@ -622,13 +622,16 @@ E.g. in member initializers, prepend `_` to the argument name shadowing the 622 | member name: 623 | 624 | ```c++ 625 | -class AddressBookPage 626 | +struct AddressBookPage
MarcoFalke commented at 3:54 PM on July 25, 2019:According to clang-format, the
{comes on the same linein doc/developer-notes.md:627 in 5bc447b924 outdated
621 | @@ -622,13 +622,16 @@ E.g. in member initializers, prepend `_` to the argument name shadowing the 622 | member name: 623 | 624 | ```c++ 625 | -class AddressBookPage 626 | +struct AddressBookPage 627 | { 628 | - Mode m_mode;
MarcoFalke commented at 3:54 PM on July 25, 2019:members should start with
m_according to the developer notes
promag commented at 4:40 PM on July 25, 2019:- Class member variables have a
m_prefix.
This is now a
struct.
sipa commented at 4:43 PM on July 25, 2019:Structs and classes are the same thing in C++. Only default visibility is different.
MarcoFalke commented at 3:55 PM on July 25, 2019: memberNot sure what is being "fixed" here
DrahtBot added the label Docs on Jul 25, 2019promag commented at 4:20 PM on July 25, 2019: member@MarcoFalke in the example the constructor argument wouldn't shadow the member.
promag force-pushed on Jul 25, 2019in doc/developer-notes.md:632 in 22b08eab54 outdated
630 | 631 | -AddressBookPage::AddressBookPage(Mode _mode) 632 | - : m_mode(_mode) 633 | + AddressBookPage(Mode _m_mode, int _m_index) 634 | + : m_mode(_m_mode) 635 | + , m_index(_m_index)
MarcoFalke commented at 4:57 PM on July 25, 2019:This is not stable with the https://github.com/bitcoin/bitcoin/tree/master/contrib/devtools#clang-format-diffpy script
promag commented at 5:11 PM on July 25, 2019:😢
promag force-pushed on Jul 25, 2019promag force-pushed on Jul 26, 2019laanwj commented at 1:23 PM on July 29, 2019: memberI still don't get it … can you please keep changes contained to what you're actually fixing, and not change code structure at the same time
promag commented at 1:40 PM on July 29, 2019: membercan you please keep changes contained to what you're actually fixing, and not change code structure at the same time
done
I still don't get it
the example is wrong considering the comment:
E.g. in member initializers, prepend
_to the argument name shadowing the member name:so in order to be correct the argument must be the same as the member..
MarcoFalke commented at 1:47 PM on July 29, 2019: memberE.g. in member initializers, prepend _ to the argument name shadowing the member name:This is wrong. We prepend members with
m_and pass arguments withoutm_. There should never be a shadow.promag commented at 1:52 PM on July 29, 2019: member@MarcoFalke right, that's why initially I had
struct AddressBookPage { Mode modeDo you prefer to drop this case then?
MarcoFalke commented at 2:03 PM on July 29, 2019: memberDo you prefer to drop this case then?
Yes, if there is an incorrect statement in the notes, it should be removed.
ryanofsky commented at 3:14 PM on July 29, 2019: memberThis is wrong. We prepend members with
m_and pass arguments withoutm_. There should never be a shadow.FWIW (feel free to ignore this comment), I don't think it makes sense to prefix struct members with
m_. The point ofm_is to make member function code more readable, so readers will not confuse member variables with argument variables and local variables. In python, you wouldn't prefix members withm_because you would sayself.instead. In a struct, you shouldn't prefix members withm_because there shouldn't be any non-trivial code using implicitthis. Structs shouldn't any nontrivial member functions. But they could have simple helpers methods likeSerializationOp,operator<, or convenience constructors where shadowing could happen, so it'd be reasonable to have convention for shadowing.Anyway, I don't think we need to have a whole discussion about code style. I'm fine with any change you want to make. I'm just responding to the "this is wrong" claim above, which I don't think is factual, just expressing a different preference.
MarcoFalke commented at 3:20 PM on July 29, 2019: memberYeah, I assumed
structis treated the same asclasswhen it comes to them_prefixpromag commented at 3:24 PM on July 29, 2019: memberI just want to fix the example which is obviously wrong in regards to shadowing.
ryanofsky commented at 3:32 PM on July 29, 2019: memberI just want to fix the example which is obviously wrong in regards to shadowing.
Could drop the example and comment about shadowing since it should come up much more rarely now. Or use:
struct AddressBookPage { AddressBookPage(Mode _mode) : mode(_mode) {} Mode mode; };or
class AddressBookPage { public: AddressBookPage(Mode mode) : m_mode(mode) {} private: Mode m_mode; };sipa commented at 4:51 PM on July 29, 2019: memberI think I always interpreted that section (and intended it) to mean
structs andclasses both get them_treatment. However, I do see that isn't very obvious from the text, and #16461 (comment) gives a pretty reasonable argument why it may be preferable not to apply it to structs.So I guess we should clarify it, but I don't have a strong opinion either way.
promag commented at 7:52 AM on July 30, 2019: memberI think we could have POD members without
m_prefix.laanwj commented at 2:01 PM on July 31, 2019: memberI think we could have POD members without m_ prefix.
Was about to say, that discussion is about POD versus OOP encapsulation, not about
classversusstructper se—although there's definitely overlap between those distinctions how they're used normallyryanofsky commented at 2:09 PM on July 31, 2019: memberI think PODness is orthogonal here. Take a struct like
InitInterfaces. It is definitely not a POD. But it has no methods and makes no use of implicit*this, so there is little reason to prefix its members withm_.[EDIT] Other examples:
WalletAddress,WalletTx:MarcoFalke commented at 3:21 PM on July 31, 2019: memberAgree that whether something is integer or not should not influence the
m_stylepromag commented at 11:46 PM on July 31, 2019: memberRight, POD members must be POD too.
makes no use of implicit *this
Yup, should be enough to not require
m_. The problem is that later on methods could be added which would screw existing member names.I'll hold on with this until we clarify the
m_treatment, otherwise I'm tempted to either remove the example of just close this.laanwj commented at 1:06 PM on August 1, 2019: memberI think PODness is orthogonal here
OK, yes, POD is the not the right name either. It depends on whether the fields are supposed to be accessed externally or in methods.
otherwise I'm tempted to either remove the example of just close this.
I'd say let's just remove this example.
fanquake added the label Waiting for author on Aug 14, 2019promag commented at 10:39 AM on August 14, 2019: memberYes, will do.
promag force-pushed on Aug 28, 2019promag renamed this:doc: Fix code example in developer notes
doc: Tidy up shadowing section
on Aug 28, 2019doc: Tidy up shadowing section 9452802480promag force-pushed on Aug 28, 2019MarcoFalke commented at 5:59 PM on August 28, 2019: memberunsigned ACK 9452802480bd154e23771230bbdfebde1dbaa941
ryanofsky approvedryanofsky commented at 7:25 PM on August 28, 2019: memberACK 9452802480bd154e23771230bbdfebde1dbaa941
fanquake approvedfanquake commented at 12:16 AM on August 29, 2019: memberACK 9452802480bd154e23771230bbdfebde1dbaa941 - Thanks for following up.
fanquake removed the label Waiting for author on Aug 29, 2019fanquake referenced this in commit 085fe76299 on Aug 29, 2019fanquake merged this on Aug 29, 2019fanquake closed this on Aug 29, 2019PastaPastaPasta referenced this in commit 5afb8b7e67 on Jun 27, 2021PastaPastaPasta referenced this in commit be0b004a47 on Jun 28, 2021PastaPastaPasta referenced this in commit f74cacdfcf on Jun 29, 2021PastaPastaPasta referenced this in commit 7d3cb7e375 on Jul 1, 2021PastaPastaPasta referenced this in commit 463a535bab on Jul 1, 2021PastaPastaPasta referenced this in commit d02d7f0eec on Jul 12, 2021PastaPastaPasta referenced this in commit ee46c9545e on Jul 13, 2021DrahtBot locked this on Dec 16, 2021
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 00:14 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me