Код: Выделить всё
struct DefaultSettings {
std::string tcpIpAddress = "127.0.0.1";
uint16_t tcpPort = 1993; // Marked as magic number!
}
В этой ситуации Clang-tidy предложил бы следующее:
struct DefaultSettings {
std::string tcpIpAddress = "127.0.0.1";
static constexpr uint16_t defaultTcpPort = 1993;
uint16_t tcpPort = defaultTcpPort;
}
и теперь 1993 больше не волшебство ...
Следуя той же строке рассуждений, на самом деле это должно быть похоже на это:
Код: Выделить всё
struct DefaultSettings {
static constexpr std::string_view defaultIpAddress = "127.0.0.1";
std::string tcpIpAddress = defaultIpAddress;
static constexpr uint16_t defaultTcpPort = 1993;
uint16_t tcpPort = defaultTcpPort;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... magic-numb
Мобильная версия