torognes / swarm

A robust and fast clustering method for amplicon-based studies
GNU Affero General Public License v3.0
121 stars 23 forks source link

code modernization (long-term task, very low priority) #144

Closed frederic-mahe closed 4 years ago

frederic-mahe commented 4 years ago

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
frederic-mahe commented 4 years ago

All trivial #define have been removed or replaced. I'll open more focused issue as our code modernization project progresses.