Weigh in - Prefixes for Globals and Class Members

Emily Shaffer emilyshaffer at google.com
Fri Oct 26 04:01:22 AEDT 2018


There was some discussion in IRC, but I wanted to make sure people who read
the maillist also got a chance to weigh in.

https://gerrit.openbmc-project.xyz/c/openbmc/docs/+/14712

This is a proposal to adjust the language of our C++ Style Guide to allow
repo maintainers to require or encourage prefixes based on variable scope:

```
constexpr int gValue;

class Foo {
  private:
    bool mFlag;
  public:
    void Bar() {
      int thing;
      if (mFlag && gValue < 0) {
        thing++;
      }
    }
}
```

The great thing about this is that you have a much stronger guarantee that
you won't end up with shadowed variables - it becomes almost impossible to
name your local in a way that collides with a larger-scoped variable you
forgot about.

That said, there's some question about how and whether to standardize
across all of OpenBMC. Renaming variables in all our repos would be a big
effort, and some maintainers might prefer different prefixes than others -
for example, canonical indicators for member variable include mFooBar,
m_fooBar, _fooBar, fooBar_,....

If you've got some strong opinions on the subject, come weigh in and help
us figure out the right language.

Personally, I just want the language to allow me to start enforcing
prefixes in repos I comaintain, without being overly prescriptive; if
you've got a different opinion or a better idea of phrasing, I wanna hear
it.

Emily
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20181025/27305b99/attachment-0001.html>


More information about the openbmc mailing list