Remix.run Logo
▲ raincole 2 days ago

I honestly don't think total = a.sum() is any less explicit than for (size_t i = 0; i <= n; i++) total += a[i]. If anything, a.sum() is more explicit as at least it expresses the programmer's intention explicitly. The loop is one more layer between the reader and the writer's intention, without faithfully reflecting what happens on the bare metal. So it's the worst of both worlds.

▲bmandale 2 days ago | parent [-]

A toy example is meant to demonstrate a principle. Toy examples often have alternative ways they can be written, but the concept they are meant to demonstrate requires the whole machinery being employed. Furthermore, how do you think .sum is implemented?