You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/02/17 16:03:24 UTC

[GitHub] [geode-native] mreddington opened a new pull request #925: Replaced loops with algorithms.

mreddington opened a new pull request #925:
URL: https://github.com/apache/geode-native/pull/925


   The idea is to begin raising the level of abstraction in implementation code. The only thing a `for` loop tells you is there's a loop, and you are left to deduce the intent of the loop in what is usually already a large function. Algorithms give names to loops and remove the pedantic details of the actual loop construct. In some instances, a range-for might appear to be more concise code, if it's only 2 (short) lines, but it still doesn't name the algorithm. If the code has gotten a little ugly, then I suggest helper functions that name the intent of the returned lambda and does the capture:
   
   ```
   auto do_the_work(type &param_to_capture) {
       return [&param_to_capture](std::shared_pointer<Cacheable> &thing) { /*body*/ };
   }
   ```
   
   So that the uglier algorithm code can look a little cleaner:
   
   ```
   std::for_each(std::begin(v), std::end(v), do_the_work(context));
   ```
   
   I posit we could replace nearly every loop in the NC with algorithms, as almost all of what happens is indeed either straight looping across a range, generating, or copying.
   
   Finally, with C++11, we get execution policies, which means where available, we can execute in an unsequenced order and let the STL suss out the details. It would at the very least express that particular part of the code has more liberty than usual.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode-native] pivotal-jbarrett commented on pull request #925: Replaced loops with algorithms.

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on pull request #925:
URL: https://github.com/apache/geode-native/pull/925#issuecomment-1043201460


   I love this! The issue I take with this PR is you promise:
   ```c++
   std::for_each(std::begin(v), std::end(v), do_the_work(context));
   ```
   but gave me:
   ```c++
   std::for_each(std::begin(v), std::end(v), [](){
     // the body of the loop reformatted as a lambda
   });
   ```
   Is this just the start?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org