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

  1. using namespace std
  2. using std endl in a loop
  3. index based for when range-for fits better
  4. rewriting std algorithms
  5. using C array over std array
  6. any use of reinterpret cast
  7. casting away const
  8. not knowing map bracket inserts element
  9. ignoring const-correctness
  10. not knowing string literal lifetime
  11. not using structured bindings
  12. out-params instead of returning a struct
  13. not using constexpr
  14. forgetting to mark destructor virtual
  15. thinking class members init in order of init list
  16. not knowing about default vs value initialization
  17. MAGIC NUMBERS
  18. modifying a container while looping over it
  19. returning std move of a local
  20. thinking std move moves something
  21. thinking evaluation order is left to right
  22. unnecessary heap allocations
  23. not using unique ptr and shared ptr
  24. not using make unique and make shared
  25. any use of new and delete
  26. any manual resource management
  27. thinking raw pointers are bad
  28. using shared ptr when unique ptr would do
  29. thinking shared ptr is thread-safe
  30. mixing up const ptr vs ptr to const
  31. 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