News for hackers. Stuff that matters.
Re:It’s time to move on from OOP? by protomolecule on Monday July 22, 2019 @02:58PM (#20501149)
"Yeah, no, you are redefining factorial in terms of different `pred` functions, and I'm simply defining `prev` without redefining factorial."

No, you are not simply defining `prev`, you are creating a new class using `computer` as a base and supplying all its methods with the new definition of `prev`.

Let me complete your example:

    class computer = object(self)

      method factorial x = 
        if x = 0 
        then 1 
        else x * self#factorial (self#pred x)

      method pred x = x - 1

    end

    class computer_enhanced = object
      inherit computer
  
      method pred x = x
    end

    obj_computer = new computer
    obj_computer.factorial(5) //still works 

    obj_computer_enhanced = new computer_enhanced
    obj_computer_enhanced.factorial(5) //stack overflow
And the same with my example:

    let rec fact(x, prev) = if x <= 1 then 1 else x * fact(prev(x), prev);;
    let factorial(x) = fact(x, fun x -> x-1);;
    let enhanced_factorial(x) = fact(x, fun x -> x);;

    factorial(5);; (*works*)
    enhanced_factorial(5);; (*stack overflow*)
In both cases the old `factorial` works and the enhanced one fails.
Re:It’s time to move on from OOP? by ernst_klim on Monday July 22, 2019 @04:55PM (#20502241)
> In both cases the old `factorial` works and the enhanced one fails.

Does

   class computer_enhanced = object
      inherit computer
  
      method prev x = x
   end
tells you that factorial definition changed and that it's dependent on prev? No.

Does

    fact(x, fun x -> x) 
tells you that this function's behavior depends on `fun x -> x`? Yes.
Re:It’s time to move on from OOP? by protomolecule on Tuesday July 23, 2019 @06:47AM (#20505744)
`factorial` definition hasn't changed, what changed is its implicit parameter. The word 'inherit' tells you that all methods of the `computer` class are potentially affected, including `factorial` unless you can see in `pred`'s contract that it affects only `factorial`.

If you call your class `computer` and put a bunch of unrelated methods in it, then, yes, you are in big trouble, but you can abuse anything - you can create a data structure with hundreds of data members and make all your 'pure' functions take and return it.

To sum it up: I see your point, but I don't think that it's a fatal flow of OOP, it's just a way to abuse it.