The goal here is to record and discuss code patterns that could or should be modernized for swarm's long-term maintainability, this is not a to-do list per se. C++ norms and compilers are getting stricter and smarter, with loads of new compile-time checks, my opinion is that we should try to get the best out of it.
(and yes, I've started to read C++ books, so I am going to be very annoying for a couple months)
prefer consts, enums, and inlines to #define
(from Scott Meyers' Effective C++: 55 Specific Ways to Improve Your Programs and Designs)
The idea is that the compiler does a better job handling these declarations than the preprocessor. If the declaration is seen by the compiler, there is no duplication in the object code, and the item is added to the symbol table. For instance in swarm.h:
#define MAX_THREADS 256
// could be replaced with:
const int64_t MAX_THREADS = 256;
# or
constexpr int64_t MAX_THREADS = 256; // see C++ core guidelines
The goal here is to record and discuss code patterns that could or should be modernized for swarm's long-term maintainability, this is not a to-do list per se. C++ norms and compilers are getting stricter and smarter, with loads of new compile-time checks, my opinion is that we should try to get the best out of it.
(and yes, I've started to read C++ books, so I am going to be very annoying for a couple months)
prefer
consts
,enums
, andinlines
to#define
(from Scott Meyers' Effective C++: 55 Specific Ways to Improve Your Programs and Designs)
The idea is that the compiler does a better job handling these declarations than the preprocessor. If the declaration is seen by the compiler, there is no duplication in the object code, and the item is added to the symbol table. For instance in
swarm.h
: