31 nooby cxx habits you need to ditch
六月 11, 2022 [c++] #c++31 nooby cxx habits you need to ditch
31 nooby cxx habits you need to ditch
- using namespace std
- using std endl in a loop
- index based for when range-for fits better
- rewriting std algorithms
- using C array over std array
- any use of reinterpret cast
- casting away const
- not knowing map bracket inserts element
- ignoring const-correctness
- not knowing string literal lifetime
- not using structured bindings
- out-params instead of returning a struct
- not using constexpr
- forgetting to mark destructor virtual
- thinking class members init in order of init list
- not knowing about default vs value initialization
- MAGIC NUMBERS
- modifying a container while looping over it
- returning std move of a local
- thinking std move moves something
- thinking evaluation order is left to right
- unnecessary heap allocations
- not using unique ptr and shared ptr
- not using make unique and make shared
- any use of new and delete
- any manual resource management
- thinking raw pointers are bad
- using shared ptr when unique ptr would do
- thinking shared ptr is thread-safe
- mixing up const ptr vs ptr to const
- ignoring compiler warnings
链接
https://www.youtube.com/watch?v=i_wDa2AS_8w&ab_channel=mCoding https://www.youtube.com/watch?v=UCIKbUvEKfI&ab_channel=ACCUConference