NL.16 is ambiguous

未关闭 适合新手
#2,344 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp, markdown
领域
documentation

调研方向

阅读 NL.16 指南以及 issue #962、#977 和 #980 中引用的讨论,然后查看 commit edbfc3b 中先前的澄清。该 issue 提议添加两个代码示例中的一个,以明确首选顺序。完成标准是 NL.16 清楚说明首选哪种顺序。

由索引模型根据 Issue 内容生成。

描述

Previously discussed in #962, #977, #980.

The recommendation according to the guideline is:

When declaring a class use the following order

  • types: classes, enums, and aliases (using)
  • constructors, assignments, destructor
  • functions
  • data

Use the public before protected before private order.

These are two different dimensions, kind (types, special member functions, functions, data) and access (public, protected, private), without clearly stating which takes priority.

Discussion from editors on previous issues (i.e. comment which appears to reference comment) seems to indicate that access takes priority over kind:

class X {
public:
    void f();
    int i;
private:
    void g();
    int j;
};

At the same time, NL.16 was updated with the goal of clarifying, adding the text:

Sometimes, the default order of members conflicts with a desire to separate the public interface from implementation details. In such cases, private types and functions can be placed with private data.

Here, it's stated that "a desire to separate the public interface from implementation details" (i.e. grouping every kind of public member together, as in the above snippet) is in conflict with "the default order of members." This seems to indicate that this is not the default, which would mean that the default order of members is instead to prioritize kind over access:

class X {
public:
    void f();
private:
    void g();
public:
    int i;
private:
    int j;
};

So, the guideline as written does not clearly explain which dimension takes priority, and searching through the repository history shows that when this came up previously, there were two simultaneous but contradictory resolutions.

Suggestion: Provide one of the two above snippets as an unambiguous example of NL.16 showing the preferred first choice (when you have no constraints or better ideas).

主要语言
CSS
星标
45.5k
派生
5.6k
平均合并
6 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

isocpp/CppCoreGuidelines 的其他 Issue

查看 isocpp/CppCoreGuidelines 的全部 Issue

相似的 Issue

更多 Documentation Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。