Hi all, I am busy 'improving' a small part of the code to use an underscore for class members. I think this helps fight bugs when converting C functions to class methods. For example, a SPPath function may define a temporary variable 'curve', but that one will hide the class's own 'curve' variable (inherited from SPShape). Since the class hierarchy is quite long at places, this is not so easily spotted. So I think the _* stuff for members is really nice and clarifies code a lot.
However, now I read in our codestyle document:
* Underscore as first character of identifiers Please consider that the C++ standard reserves _* identifiers [17.4.3.1.2]: "Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace".
Hmm, quite a large part of our codebase already uses _* to signify class members. I think this is somewhat common practice? Do we agree to ignore this text in the C++ standard? And shall we change our codestyle text to indicate that we use _* to indicate class members?
(I hope this does not result in long maillist discussions... Please answer yes or no. I am already convinced that _* is better than without, and cannot be convinced otherwise. (I _may_ consider 'm_' but it is perhaps overly verbose?))
Thanks, Johan
On 17-1-2012 22:14, Johan Engelen wrote:
However, now I read in our codestyle document:
http://wiki.inkscape.org/wiki/index.php/Coding_Style#Underscore_as_first_cha...
On 17-1-2012 22:14, Johan Engelen wrote:
Hi all, I am busy 'improving' a small part of the code to use an underscore for class members. I think this helps fight bugs when converting C functions to class methods. For example, a SPPath function may define a temporary variable 'curve', but that one will hide the class's own 'curve' variable (inherited from SPShape). Since the class hierarchy is quite long at places, this is not so easily spotted. So I think the _* stuff for members is really nice and clarifies code a lot.
However, now I read in our codestyle document:
- Underscore as first character of identifiers Please consider that the C++ standard reserves _* identifiers
[17.4.3.1.2]: "Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace".
Or did I misinterpret, and does it mean that ::_* is reserved, but JohanClass::_hello is perfectly fine?
Thanks, Johan
On Jan 18, 2012, at 8:40 AM, Johan Engelen wrote:
On 17-1-2012 22:14, Johan Engelen wrote:
Hi all, I am busy 'improving' a small part of the code to use an underscore for class members. I think this helps fight bugs when converting C functions to class methods. For example, a SPPath function may define a temporary variable 'curve', but that one will hide the class's own 'curve' variable (inherited from SPShape). Since the class hierarchy is quite long at places, this is not so easily spotted. So I think the _* stuff for members is really nice and clarifies code a lot.
However, now I read in our codestyle document:
- Underscore as first character of identifiers Please consider that the C++ standard reserves _* identifiers
[17.4.3.1.2]: "Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace".
Or did I misinterpret, and does it mean that ::_* is reserved, but JohanClass::_hello is perfectly fine?
Yes, you just hit on it.
General identifiers can not start with an underscore, but members of a class are as you noted.
_JohanClass::_hello would be bad, but JohanClass::_hello is fine.
Oh, and there could be a minor variation to consider. Some coders like to put the underscore at the end, not beginning. Given the existing prefixing all over our code, staying consistent might be good. But I did want to highlight the option.
2012/1/17 Johan Engelen <jbc.engelen@...2592...>:
- Underscore as first character of identifiers
Please consider that the C++ standard reserves _* identifiers [17.4.3.1.2]: "Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace".
Hmm, quite a large part of our codebase already uses _* to signify class members. I think this is somewhat common practice? Do we agree to ignore this text in the C++ standard? And shall we change our codestyle text to indicate that we use _* to indicate class members?
It means _* is allowed everywhere except the global namespace. It's not allowed for types, functions and global variables, but in the global namespace only. It's OK to have a function that starts with _ in the Inkscape or Geom namespaces.
Also reserved are all names that start with two underscores, and all names that start with an underscore and a capital letter, in all scopes. It's OK to have members like _data and _largeFoo, but not _Data or _Large_Foo. http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-...
In my experience, underscores at the end are harder for the eye to 'parse', and look weird when the member itself is an object, e.g. object_.doSomething()
Regards, Krzysztof
participants (3)
-
Johan Engelen
-
Jon Cruz
-
Krzysztof Kosiński