Style: Consider using trailing underscores for protected/private attributes and methods in C++

Open
#398 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp

Research direction

Read the linked Google C++ Style Guide and survey the repository's C++ naming conventions; no files or tests are named in the issue. Compare the proposed leading-underscore convention with the trailing-underscore alternative and confirm the preferred project-wide rule. Done would require an agreed convention and the repository-wide changes that follow from it.

Written by the indexing model from the issue text.

Description

question

Currently we follow Google's C++ Style guide and use trailing underscores for protected/private attributes

class A {
 public:
    void a_method();
    int a;
 protected:
    void b_method();
    int b_;
 private:
    void c_method();
    int c_;
};

I propose that we switch to using leading underscores for both attributes and methods in our C++ code base.

class A {
 public:
    void a_method();
    int a;
 protected:
    void _b_method();
    int _b;
 private:
    void _c_method();
    int _c;
};

Alternatives

Use trailing underscores for both methods and attributes. This would be more C++-y and less Pythonic, but IMO less readable.

Dominant language
C++
Stars
31
Forks
36
Avg merge
1d 9h
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dwavesystems/dwave-optimization

All issues in dwavesystems/dwave-optimization

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.