Comments by "MrAbrazildo" (@MrAbrazildo) on "how NASA writes space-proof code" video.
-
0:02, pretty? Signed var is faster.
0:10, in C++ it's possible to make a class that always implicitly checks if the pointer is nullptr.
1:17, I would not use linked lists neither, which rarely are faster, can't be used in STL algorithms, and forces you to make raw loops. For instance, if 'e' was a std::vector, this whole f() would be dismissed:
const auto Result = [](const std::vector <int> &e, const int search) {
const auto Result = std::find (e.cbegin(), e.cend(), search);
return Result == e.cend() ? null : *Result;
} (e, search);
1:24, C++ containers use to have iterators delimiting begin and end, putting the programmer in a range loop by default. For instance, std::forward_list performes a linked list in 1 direction, and has begin/end f()s to give those iterators.
1:55, or just use std::vector, which will free the memory, if its object no longer exists. It hasn't the use after free protection, but it's possible to wrap it in a class, to check that automatically.
3:20, but if that variable must travel alonside f()s, as read-only, and be changed only at the Nth f() called, C can't protect it. C++ has the solution: hide it in a class, making that f() friend of it, so that only it'll be allowed to change the variable.
4:01, C++ has the attribute [[nodiscard]], meaning that a compile error will raise, if the return value is not treated.
5:40, I always use pedantic, because it has good rules. But Werror forbids me to run the app. I always end up cleaning all warnings I turned on, but not always I want to do it right away, which may be less productive. Same thing for implicit conversions. So I don't turn on all warnings.
So we can realize that using C++ is a big improvement for defensive code, at least over C.
1