Things To Look Out For In Reviews: Difference between revisions
Jump to navigation
Jump to search
(De-meta-isise "Deprecations and Removal" =sections= are about the document itself, all guidelines are to be added to "Newly-Added Things". Add request for QT_REMOVED_SINCE \note for prior Qt versions.) |
(Add section on std::optional) |
||
Line 70: | Line 70: | ||
* Namespaces are called QtFoo, not QFoo. '''Rationale:''' prior art: QtConcurrent, Qt, QtPrivate, ... | * Namespaces are called QtFoo, not QFoo. '''Rationale:''' prior art: QtConcurrent, Qt, QtPrivate, ... | ||
== Class-Specific Usage Guidelines == | |||
=== std::optional === | |||
* Don't use value(), has_value(), use pointer-compatible subset: if (opt), *opt, opt->foo. '''Rationale:''' has_value() is just needless verbosity, but value() is downright dangerous, because it's a checked version of op* and throws an exception if !*this. | |||
* Avoid the default constructor, explicitly use std::nullopt. '''Rationale:''' GCC has a long-standing bug which causes the default constructor to emit maybe-unused warnings. '''Example:''' (incl. error message and links to upstream bug reports) https://codereview.qt-project.org/c/qt/qtlanguageserver/+/413811 | |||
== Deprecations and Removals == | == Deprecations and Removals == |
Revision as of 08:23, 11 January 2024
This page is a low-entry-bar staging area for potential project-wide guidelines. After each release, we should go over each of these and decide whether we keep them here, or, preferably, fold them into Review Policy, API Design Principles, Commit Policy, Qt Coding Style, Coding Conventions or a new or existing QUIP.
Canons
Be aware of the following generally-accepted principles:
- KDE Binary Compatibilty Page (a must-read, must-understand for anyone doing API reviews)
- CppCoreGuidelines (a lot of stuff of doubtful quality in there these days, but if you get an F.3 comment, that's where to find what that means)
- API Design Principles
- Commit Policy
- Qt Coding Style
- Coding Conventions
Newly-Added Things
When adding a new Thing, don't forget to provide rationale.
Public Headers
- Don't move code around when changing public headers. Prefer adding new keywords or attributes on a separate line. Rationale: moving code around makes API-change-reviews needlessly hard. Example: Bad: https://codereview.qt-project.org/c/qt/qtmultimedia/+/528314/1/src/multimedia/video/qvideoframe.h Good: https://codereview.qt-project.org/c/qt/qtbase/+/528393/2/src/corelib/kernel/qpointer.h#34
Includes
- Include Qt headers always as <QtModule/qheader.h>. Rationale: it's probably the fastest way to include the file while maintaining compatibility with non-per-module-include build systems.
- Group includes in descending specificity / ascending generality: first, module headers, then dependenee Qt modules, then QtCore headers, then C++ headers, then C headers, then platform / 3rd-party headers. Separate groups with blank lines. In each group, sort alphabetically. Rationale: Like in CMakeLists's SOURCES, or removed_api.cpp, or tests, ordering code minimizes conflicts between independent changes.
Enums
- add a trailing comma to end of enumerators if a line break follows. Rationale: prevents the previous line from needing to change when adding more. Example: https://codereview.qt-project.org/c/qt/qtremoteobjects/+/528328/comment/9b8677ff_4ce9831a/
- enums should either be scoped or have an explicit underlying type. Rationale: prevents the enum's underlying_type to change (which would be BiC). References: http://eel.is/c++draft/enum#dcl.enum-7.sentence-3, https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B#The_Do's_and_Don'ts (Point 3)
- New enumerators should be documented as new for version VERSION with
\value [since VERSION]
See also qdoc's \value command - Be clear about what the purpose of the enum is:
- An enumeration? Then don't = any values.
- A base for QFlags? Then = 0x each value (yes, hex).
- A strong typedef? Are relevant arithmetic operators defined?
- Anything else? Consider using a class instead. Rationale: gives you more control over the the API.
- Try to make sure {} (value-initialization, ie. value 0) means "default". Rationale: Since C++11, {} means "default" (default constructor, e.g.). Also, having 0 be the default saves some space as a) a global variable with initial value 0 doesn't need to be stored in the executable (it ends up in BSS, not DATA) and b) it's easier to construct in a register than a non-zero value (xor r,r), saving executable code size when such types are defaulted arguments.
New Classes
Documentation
- Is the documentation for the class complete and in good shape (grammar, style, correctness)?
- Is the class documented as new with
\since
? - Does the class provide a good overview section?
- Is it properly linked from related API and overview documentation? In particular, check whether similar or related classes have any
\ingroup
commands and whether it makes sense the class should also have it! - Should the class be mentioned in the What's New in Qt 6 overview documentation?
Value Classes
- Make sure new (value) classes follow the draft value-class mechanics QUIP-22.
- Don't use QSharedDataPointer for the d-pointer anymore. Use QExplicitlySharedDataPointer for the d-pointer, with the macros to allow move-special-member-functions to be =default'ed. Rationale: We used to be able to switch between raw pointer, QSDP and QESDP without affecting BC, but the macros now bake the choice of QSDP or QESDP into the ABI, so we need to get things right from the get-go. References: Comparison of (proposed) QIntrusiveSharedPointer to QSDP and QESDP, highlighing the latter two gotchas (const propagation, eager detaching...)
- Don't forget Q_DECLARE_SHARED. Rationale: it provides Q_DECLARE_TYPEINFO and ADL swap() to the class.
- Don't add Q_DECLARE_METATYPE. Rationale: it's automatic now.
Polymorphic Classes
- Make dtor out-of-line, even if empty (then =default it). Rationale: pins the vtable to a single TU (and prevents -Wweak-vtable warnings). References: https://bugreports.qt.io/browse/QTBUG-45582
RAII Classes
(tbd)
Namespaces
- Namespaces are called QtFoo, not QFoo. Rationale: prior art: QtConcurrent, Qt, QtPrivate, ...
Class-Specific Usage Guidelines
std::optional
- Don't use value(), has_value(), use pointer-compatible subset: if (opt), *opt, opt->foo. Rationale: has_value() is just needless verbosity, but value() is downright dangerous, because it's a checked version of op* and throws an exception if !*this.
- Avoid the default constructor, explicitly use std::nullopt. Rationale: GCC has a long-standing bug which causes the default constructor to emit maybe-unused warnings. Example: (incl. error message and links to upstream bug reports) https://codereview.qt-project.org/c/qt/qtlanguageserver/+/413811
Deprecations and Removals
- Does the documentation reflect the deprecation, and mention the version it is first deprecated for (see also qdoc's \deprecated command? Does it give the user a rationale, as well as a suggestion for alternatives?
- for QT_REMOVED_SINCE, does the new function contain a "\note In Qt versions prior to 6.x, this function took/was ..."?
Decided To Keep Here
(make a proper subsection grouping when moving stuff here)