Skip to main content
Post Made Community Wiki by webvitaly
Source Link

If it's just a short piece of code that does something relatively simple in a hard-to-understand way, I'd shift the "quick understanding" in an extended comment and/or an unused alternative implementation, like

#ifdef READABLE_ALT_IMPLEMENTATION

   double x=0;
   for(double n: summands)
     x += n;
   return x;

#else

   auto subsum = [&](int lb, int rb){
          double x=0;
          while(lb<rb)
            x += summands[lb++];
          return x;
        };
   double x_fin=0;
   for(double nsm: par_eval( subsum
                           , partitions(n_threads, 0, summands.size()) ) )
     x_fin += nsm;
   return x_fin;

#endif