[cmake-developers] Questions about coding conventions

Daniel Pfeifer daniel at pfeifer-mail.de
Fri Jun 10 09:30:05 EDT 2016


Hi,

By looking at the CMake source code, there are some inconsistencies
regarding coding conventions. This is not a big problem and fixing
them probably does not have a high priority.
I would like to know what conventions to follow for new code.

Formatting: No longer an issue. A .clang-format is provided and most
inconsistencies have disappeared.

Braces around single conditional statements: This is currently not
consistent. Should they be avoided? Should they be required? We could
add the missing ones with clang-tidy. If we want them.

Naming conventions: Classes are named  cmLikeThis. Member functions
and member variables are named LikeThis. Local variables are named
likeThis. Members are always accessed with `this->`. So far it is
pretty consistent. But how to name free functions and macros? I have
seen all kinds of variations.

`const T` or `T const` (also: `const T&` or `T const&`): Currently,
CMake uses both. I have not analyzed which one dominates.

Passing and returning strings: We have `const char*`, `std::string`,
and `std::string const&`. Unifying this can affect performance.
Storing `const char*` in a `std::string` creates a (potentially
unneded) copy (assuming it is not null). `const char*` can distinguish
invalid from empty. Do we actually need this distinction? Or should we
assume empty==invalid and always prefer `std::string const&`
arguments? Or should we introduce a C++17-like cmStringView?

cheers, Daniel


More information about the cmake-developers mailing list