NL.16 is ambiguous

Abierto Apto para principiantes
#2,344 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
75/100
Tipo de issue
Documentación
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp, markdown

Línea de trabajo

Lee la directriz NL.16 y las discusiones mencionadas en los issues #962, #977 y #980. Después, consulta la aclaración anterior en el commit edbfc3b. El issue propone añadir uno de sus dos ejemplos de código para dejar explícito el orden preferido. Se considera terminado cuando NL.16 indique claramente qué orden se prefiere.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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).

Lenguaje dominante
CSS
Estrellas
45.5k
Forks
5.6k
Merge medio
6 min
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de isocpp/CppCoreGuidelines

Todos los issues de isocpp/CppCoreGuidelines

Issues similares

Más issues de Documentation

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.