by enriquto · 5y ago · 0 comments
Using bit-shift operators for input/output is a heinous crime against human dignity, basic decency and social order. Every use of it should be punished with 10 lashings, and the promoters of this atrocity should be tarred and feathered.
I'm agnostic on C++'s std stream stuff but I am pretty anti-"yes bitwise logical operators are so important that they get priority over all these symobls".
- wrong arguments types (mostly solved by libraries such as fmt tho): printf("%d", 0.5);
- too much / not enough arguments passed: printf("%d", 0, 1);
- passing unsanitized strings as template argument: printf(some_string_i_got_from_the_network_lol, arg_1, arg_2);
the << method makes these three errors impossible.
Also << does not allow you to have something like printf's %n, which writes to one of its arguments.
fmt is able to give compile-time validation of string literals, but at a hefty compile-time cost. In my opinion the best solution would be string interpolation, but we're definitely not there yet...
> - too much / not enough arguments passed: printf("%d", 0, 1);
-Wformat
> - passing unsanitized strings as template argument: printf(some_string_i_got_from_the_network_lol, arg_1, arg_2);
-Wformat-nonliteral