C++ is an easy language to make mistakes in. Lots of code that seems normal, or even natural, can have undefined behaviors that end in a segfault, or memory corruption leading to a segfault. Even code that does not crash may be inefficient, even though in many languages it would be the normal (and even fast) way of getting something done. Complicating the efforts of beginning C++ programmers are the numerous resources online, a good number of which are wrong, or show how things should be done in C, rather than C++.
In order to help the students working with us in the Decision Optimization Lab come up to speed on C++ in a research environment, I am creating the following list of resources on good practices in C++. Whenever you have a question about something in C++, check this list before accepting a random answer on Stack Overflow or one of the many other websites with answers that may be wrong. I am also including some of my own rants on various C++ topics in these lists. In addition to these links, I recommend Scott Meyer's book Effective C++, Third Edition for an overview of many good practices in C++.C++ Style
- Random number generation using C++ TR1. Always generate your random numbers using TR1.
- Issues with rand().
- Don't use atoi and other C-style conversions. Use stringstream. (article on this coming soon)
- Initialition Lists in C++. Always properly initialize your objects.