NL.16 is ambiguous

Aperta Adatta ai principianti
#2,344 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp, markdown
Ambito
documentation

Direzione di ricerca

Leggi la linea guida NL.16 e le discussioni citate negli issue #962, #977 e #980. Poi controlla il chiarimento precedente nel commit edbfc3b. L’issue propone di aggiungere uno dei due esempi di codice per esplicitare l’ordine preferito. Il lavoro è completato quando NL.16 indica chiaramente quale ordine è preferito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
CSS
Stelle
45.5k
Fork
5.6k
Merge medio
6m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di isocpp/CppCoreGuidelines

Tutte le issue di isocpp/CppCoreGuidelines

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.