Comments by "MrAbrazildo" (@MrAbrazildo) on "Coding in a Random Programming Language Everyday (Huge Mistake)" video.
-
5:53, I use to not include in advance. I wait for a compiler error ou the actual use of something by the lib. This way I can avoid unnecessary includes.
6:00, Const Correctness Principle: 1st write 'const', only thinking after a compile error. Thinking is a waste of energy, avoid doing it.
And whenever I write { } for a f(), I write its 'return' right away. So I avoid the missing return UB bug. On modern C++, a more consistent defensive method for that is to declare the returning type as 'auto'.
6:26, A << B is the highest level possible thing: B is being threw to A.
7:26, for a 1st approach, I think assert is better here: 1 line/cmd. I know it doesn't close files, but this is the 1st, and not opened.
7:33, you are throwing away 1 of the best features from C++: get rid of things automatically.
7:35, for apps, I use namespace std, to be more productive.
10:30, const auto ptr = std::find_if (new_begin, line.cend(), ::isdigit);
if (ptr == line.cend()) break; // There's no digit to the right from where the find started.
leftmost = *ptr - '0'; // '0' keeps portability. Don't use a number: unworth to be memorized.
new_begin = ptr + 1;
10:59, atoi works with char *, not char.
16:35, std::map does this. I use to implement this as 2 std::array.
16:42, this could had been just: if (gTable[i].str == slice). If str and num where 2 std::arrays, the whole f() could be:
const auto ptr = std::find (str.cbegin(), str.cend(), slice);
if (ptr == str.cend()) return -1; return num[std::distance (str.cbegin(), ptr)];
1