News for hackers. Stuff that matters.
Re:Learn more programming languages, even if you won't use them by darkhorn on Saturday April 13, 2019 @08:34AM (#19652636)
I've learned to code methods in OO languages without using loops after I've learned Erlang. No loops means less bugs.
Re:Learn more programming languages, even if you won't use them by zcw100 on Saturday April 13, 2019 @09:23AM (#19652864)
I can’t tell if this is sarcasm but if it isn’t it just proves the point. Your teammates must just love working with you. I’d love to see the look on their faces when you committed that code. “I just learned Erlang. Check out what I did without telling anyone. Suck it. Boom!”
Re:Learn more programming languages, even if you won't use them by darkhorn on Saturday April 13, 2019 @03:24PM (#19655190)
It is not sarcasm. Yes, they love working with me, they learn new things from me and they use it. Generally their face is like "o_O I wish I've learned it before". I use build-in functions of PHP and Java in way without loops, there is nothing unknown. I don't write Erlang code. Here is an example what I mean;

  <?php declare(strict_types=1);
  function fibonacci_nth(int $n): int {
      if($n === 0) return 0;
      if($n === 1) return 1;
      else return fibonacci_nth($n - 2) + fibonacci_nth($n - 1);
  }
  function fibonacci_series(int $n): array {
      return array_map('fibonacci_nth', range(0, $n));
  }

And here in Python

  class Fibonacci:
     def fibonacci_nth(self, n):
        if(n == 0): return 0
        if(n == 1): return 1
        else: return self.fibonacci_nth(n-1) + self.fibonacci_nth(n-2)
        
     def fibonacci_series(self, n):
        return [self.fibonacci_nth(x) for x in range(n+1)]
Re:Learn more programming languages, even if you won't use them by jodrellblank on Saturday April 13, 2019 @11:22PM (#19657404)
"no loops means less bugs"

But the loops will be clear and explicit. People can check if you have an off-by-one error.

Python does not support many recursive calls, after "n" gets beyond a certain number, the code will crash with a RecursionError.

That is a bug which is much harder to see. The code will crash if N < 0 for the n_th() method, which is probably a bug.

Re:Learn more programming languages, even if you won't use them by platz on Saturday April 13, 2019 @08:42AM (#19652681)
And none of those OO langs can be relied on to have tail recursion so now you a new problem
Re:Learn more programming languages, even if you won't use them by yomly on Saturday April 13, 2019 @08:48AM (#19652712)
Most non-functional languages will implement map/filter/reduce as loops under the hood, but realizing that there is an abstraction for general sequence processing frees you up to focus more on the core business logic at hand and reduces the surface area of your code for bugs.

Sure, handrolling a loop is a trivial activity that novice programmers can figure out, so you should _never_ get it wrong because you _never_ ever program tired or hurriedly under deadlines or make typos or input off by ones...

Re:Learn more programming languages, even if you won't use them by AnimalMuppet on Saturday April 13, 2019 @03:50PM (#19655339)
I don't recall exactly how many handrolled loops I've messed up in the last 10 years, but the number is either 1 or 2. Could I mess up one or two map/filter/reduces in 10 years? Is it impossible to mess them up? What about the cases they don't cover, so you use your own recursion?
Re:Learn more programming languages, even if you won't use them by jodrellblank on Saturday April 13, 2019 @10:45PM (#19657264)
OK you can write a handrolled loop almost perfectly. /Why/ are you writing ten years worth of loops - something a computer can do for you?
Re:Learn more programming languages, even if you won't use them by AnimalMuppet on Sunday April 14, 2019 @02:42PM (#19660924)
Can it? I'm working on embedded systems, in C++, with C++11-or-earlier compilers. Sometimes I need control of the exact order things happen in. Sometimes I need an action to occur either zero or one times, on the first available entry. Always I need to write code that my coworkers can read.

How much of that can a C++11 compiler do for me?