stewartmatheson / projectx

0 stars 1 forks source link

Replace explicit iterator loop with range-based for loop #24

Closed msbit closed 3 years ago

msbit commented 3 years ago

Another cute three word aphorism from one of the revered C++ boffins:

No Raw Loops

That talk in general is very good, and worth a watch, but what I've taken from that part is to lean on the STL algorithms, if they apply for the situation, and that this can make the code less noisy.

In these cases so far, using std::find_if makes it clear that we're finding one thing, based on some encapsulable predicate, and it removes the boilerplate of the loop proper.

msbit commented 3 years ago

Oh and I suspect a bunch of these PRs will trample on each other, so if you want, merge the ones that will go cleanly, and ping me to rebase the ones that won't.

stewartmatheson commented 3 years ago

Interesting. I saw Jason Turner talk about this as well in an episode. I think it was the one where he refactored doom to c++ but I can't remember TBH. Long video but worth spending a few mins scrubbing though

https://www.youtube.com/watch?v=d1BwjUlwYeg

msbit commented 3 years ago

Big fan of Turner, I'll take a look.

Also realised these comments should have been on https://github.com/stewartmatheson/projectx/pull/25 :P