• hallettj@beehaw.org
    link
    fedilink
    English
    arrow-up
    4
    ·
    6 months ago

    I pretty much always use list/iterator combinators (map, filter, flat_map, reduce), or recursion. I guess the choice is whether it is convenient to model the problem as an iterator. I think both options are safer than for loops because you avoid mutable variables.

    In nearly every case the performance difference between the strategies doesn’t matter. If it does matter you can always change it once you’ve identified your bottlenecks through profiling. But if your language implements optimizations like tail call elimination to avoid stack build-up, or stream fusion / lazy iterators then you might not see performance benefits from a for loop anyway.

    • blindsight@beehaw.org
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      6 months ago

      Yes. I know some of those words.

      Seriously, though, I’m not a programmer, but I picked up enough from context cues and background information that I think I got most of the big ideas. It’s fun to read about computer science.

      I wonder where my life would have gone if I’d made a different career choice, away from CS.