3 ms·
> A std::string in C++ makes mincemeat Using bit-shift operators for input/output is a heinous crime against human dignity, basic decency and social order. Ev
by enriquto 6y ago
> A std::string in C++ makes mincemeat
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.
- deleted 6y ago[deleted]
- rtpg 6y agoalternatively, one could consider that bit-shifting isn't nearly as common of a thing as I/O stream redirection. 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".
- leetcrew 6y agoamong other things it's just not a very friendly syntax for the common case of formatting strings and getting input. printf/scanf are much less verbose (if a bit less safe).
- rtpg 6y agoThat's a good point, actually. Beyond the "default formatting" case, it seems pretty hard to imagine a good syntax that would not be very awkward.
- jcelerier 6y agobut it removes three classes of errors entirely when compared to printf / scanf: - 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...
- account42 6y ago> - 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); -Wformat > - passing unsanitized strings as template argument: printf(some_string_i_got_from_the_network_lol, arg_1, arg_2); -Wformat-nonliteral
- jcelerier 6y agoRidiculous dogmatism