Arcane C++ rules, namespaces and overloads

Last week I needed to help a colleague that had a mysterious compiler error. The code, the original was split into multiple files, looked at first like this #include <iostream> namespace A { struct foo{}; } inline std::ostream operator<<(std::ostream& os, A::foo) {return os;} namespace B { struct bar{}; inline std::ostream operator<<(std::ostream& os, bar) {return os;} void fun() { std::cout << A::foo{}; } } int main() { B::fun(); } GCC, trying to helpful, presented multiple pages of diagnostic, enumerating all overload it considered for operator<<: char, int, unsigned int, short, long, float, B::bar, and many other depending on your includes like std::string, std::regex and so on (the list was very long).

Read more →

Commenting source code

Considerations on writing comments

Read more →

Detect member variables since C++11

Reflection is a language feature that permits to inspect and query information about types in the language itself and act accordingly. A common usage of reflection is logging and serialization. Through reflection, one could iterate over all member variable of a structure, and serialize them recursively. The same approach would then be used for deserializing. Reflection is of course not strictly necessary. It is possible to write all serialization code by hand, but like most language and library features, it enables code reuse and thus avoiding common errors and unneeded complexity.

Read more →

Setting a default editor in Microsoft Windows

Setting a editor in Microsoft Windows

Read more →

Iterating over delimited string in shell scripts

Last time I automated some jobs with my shell, I confronted with the problem of iterating over a string in bash. I needed to split the string with a specific delimiter, and iterate over the splitted substring. While I advocate that from the moment your shell scripts acquire enough logic it makes more sense to convert them to something else, this did not seem to be the case. Program invocations and string manipulation is a common tasks in shell scripts.

Read more →

Sharing data between threads

Design your data to be thread safe

Read more →