every single line of code is clear, understandable and expressive
It's been a while since I looked at C++ but that statement doesn't apply to me. For example:
for(const auto &i : data) {
ofile << i << std::endl;
}
I have no idea what that's doing or why it makes any sense. If I knew C++ better maybe that wouldn't be the case but, for example, the Ruby example someone else provided is obvious to me (and I don't work with Ruby).
It feels there's a lot of telling the machine how you want to do something going on in here (instead of what you want it to do).
I'd be really interested in hearing how this sample differs from a previous C++ implementation.
I think people sometimes feel compelled to combine auto and the range based for loop when they shouldn't. In this example the range based for loop adds clarity but the use of auto doesn't. I would have written something like:
Actually, the only thing this tells you about what you are getting out of the vector is that it can be implicitly converted to a string.
If data is a vector of, for example, pointers to const char, on each iteration this code will unnecessarily copy each item into a temporary string before printing it. Using auto would avoid this step, regardless of data's type.
Note that the typical non-range-based for loop also omits the vector item type... Is this that much less clear?:
for (int i = 0; i < data.size(); ++i) {
ofile << data[i] << std::endl;
}
I think that some amount of knowledge was assumed. You would have understood it if you had known Java. For-each loops in Java have a very similar syntax.
You probably know something that is similar to Ruby, and that's why you understand it without ever learning it. I bet that you wouldn't understand it if you didn't know any programming language at all.
It's been a while since I looked at C++ but that statement doesn't apply to me. For example:
I have no idea what that's doing or why it makes any sense. If I knew C++ better maybe that wouldn't be the case but, for example, the Ruby example someone else provided is obvious to me (and I don't work with Ruby).It feels there's a lot of telling the machine how you want to do something going on in here (instead of what you want it to do).
I'd be really interested in hearing how this sample differs from a previous C++ implementation.