Re:Chromium: Improve support for Nintendo Switch gamepads
by cmrdporcupine on Thursday March 14, 2019 @07:54AM
(#19388367)
Google C++ style guide. It's for instance variables on classes, to distinguish from local variables.
https://google.github.io/styleguide/cppguide.html#Variable_N...
Re:Chromium: Improve support for Nintendo Switch gamepads
by joshvm on Thursday March 14, 2019 @08:42AM
(#19388681)
Is there a reason for not using 'this'? I assume the risk is that you might have a scope where both this->foo and foo are valid and it's unclear which is which. You have no ambiguitiy with this->foo_, and foo (and if you forget 'this', foo_ is still clear).
Re:Chromium: Improve support for Nintendo Switch gamepads
by nolok on Thursday March 14, 2019 @10:40AM
(#19389610)
I assume it's because if a dev forgets a this somewhere as a caller/accessor, you now have two problems; whereas if they forget a _, it doesn't compile.
Re:Chromium: Improve support for Nintendo Switch gamepads
by amalcon on Thursday March 14, 2019 @10:28AM
(#19389522)
Rules like this are usually less about risk, and more about conveying information. If I see a variable ending in "_", I immediately know to look for its definition in the class rather than the local scope.
Re:Chromium: Improve support for Nintendo Switch gamepads
by pjc50 on Thursday March 14, 2019 @11:06AM
(#19389857)
It's unidiomatic?
> scope where both this->foo and foo are valid and it's unclear which is which
Ideally you'd turn on the compiler option to warn about scope hiding.
Re:Chromium: Improve support for Nintendo Switch gamepads
by joshvm on Thursday March 14, 2019 @03:52PM
(#19392925)
Maybe, though it's a common thing I've seen in setter functions or constructors:
Eg void set_foo(int foo) {this->foo = foo;}
Re:Chromium: Improve support for Nintendo Switch gamepads
by jcelerier on Thursday March 14, 2019 @08:54AM
(#19388750)
six characters to type vs 1 ?
Re:Chromium: Improve support for Nintendo Switch gamepads
by joshvm on Thursday March 14, 2019 @10:49AM
(#19389687)
You can argue that either way.
Seeing 'this' unambiguously implies instance variable. Otherwise you have to spot the underscore and be aware of the conventions in the codebase. A good IDE should highlight class variables vs locals, though.
On the other hand code can get really messy with boilerplate like this everywhere, and I personally agree with you. Although I believe Google also promotes human-readable variables over less typing.
Re:Chromium: Improve support for Nintendo Switch gamepads
by tokyodude on Thursday March 14, 2019 @01:08PM
(#19391210)
I actually think implicit "this" is a language wart. I think C++, C#, Java, Swift, etc.. would all be better languages if they required `this`. As it is, nearly every one of them ends up needing a per team naming convention to help make the code readable.
int area(int width) {
return width * height;
}
What is "height". Is it a global variable? variable in some outer scope? A member/property of the current object? Absolutely no idea.
Re:Chromium: Improve support for Nintendo Switch gamepads
by olig15 on Thursday March 14, 2019 @07:52AM
(#19388364)
I think it's because they're member variables. It makes them clear they're not local to the method.
Re:Chromium: Improve support for Nintendo Switch gamepads
by Insanity on Thursday March 14, 2019 @07:55AM
(#19388376)
At a quick glance, that does seem to be a difference with the postfixed variables! Have not yet encountered something like that in the languages I've worked with. ^^
Re:Chromium: Improve support for Nintendo Switch gamepads
by cmrdporcupine on Thursday March 14, 2019 @08:35AM
(#19388627)
Wait til you discover Hungarian notation?
https://chromium-review.googlesource.com/c/chromium/src/+/15...
e.g: switch_pro_4, dualshock_ps4_, ...
It does not happen for all variables, what is this convention? :o