News for hackers. Stuff that matters.
Re:Clever code is probably the worst code you could write by lupire on Tuesday May 21, 2024 @07:18PM (#40435382)
That's terrible! The main operation, addition, is completely hidden magic! But the completely trivial calls to .begin() and .end() are explicit!

Why would I want to add by default?

Re:Clever code is probably the worst code you could write by jcelerier on Tuesday May 21, 2024 @08:40PM (#40436074)
> The main operation, addition, is completely hidden magic

the main operation is reduction which is fairly basic computer science and taught in any non-BS curriculum - https://en.wikipedia.org/wiki/Reduction_operator (or https://en.wikipedia.org/wiki/Fold_(higher-order_function) which is the standard way to introduce this concept ; check in particular the table showcasing all the implementations in various languages). The standard reduction for a set of numbers to a number that is likely going to be the very first example in your textbook is addition.

Re:Clever code is probably the worst code you could write by Dylan16807 on Tuesday May 21, 2024 @09:26PM (#40436390)
The reduction is explicit. That's not what the complaint is about. And it's more about implementation than the actual result.

The actual operation is addition. I don't care if it's the first example, that doesn't mean you should hide it.

Imagine if print did hello world by default.

Re:Clever code is probably the worst code you could write by o11c on Tuesday May 21, 2024 @08:57PM (#40436181)
std::ranges::fold_left (since C++23) can take a range directly instead of a separated pair of iterators, and requires the explicit add.
Re:Clever code is probably the worst code you could write by psychoslave on Wednesday May 22, 2024 @09:32AM (#40440749)
Maybe the idea is that you overload your favored default as a + operator? Even more baffling certainly, but at this point I wouldn’t even be surprised this was considered a compelling argument in the mind of whoever settled this API choice. :D
Re:Clever code is probably the worst code you could write by constantcrying on Wednesday May 22, 2024 @11:28AM (#40442184)
What is hidden? It's a reduce on + starting with 0, hardly anything subtle.