News for hackers. Stuff that matters.
Re:OO in Python is mostly pointless by bcrosby95 on Thursday January 28, 2021 @12:44AM (#25938650)
The point is the graph of data dependencies in an FP system doesn't necessarily look any different than in an OO one.
Re:OO in Python is mostly pointless by andi999 on Thursday January 28, 2021 @05:21AM (#25940208)
Closures and internal state of objects are basically the same thing.
Re:OO in Python is mostly pointless by throwaway894345 on Thursday January 28, 2021 @01:13PM (#25946147)
I don't usually deal with stateful closures. In OO we often have file objects, and if you call Close() on said object, subsequent Read() invocations fail because the encapsulated state has changed. What's the closure analog for this?
Re:OO in Python is mostly pointless by lostcolony on Thursday January 28, 2021 @05:13PM (#25950164)
You've never worked with a generator before? That's a stateful function. For throwing after a file handle is closed, something like -

  const read = (fileHandle) => {
     return () => {
       if io:isOpen(fileHandle) && io:hasNext(fileHandle) => {
          return io:readNext(fileHandle)
       } else if io:isOpen(fileHandle) {return undefined
       } else {throw "File is closed"}
     } 
  }(myFile)

  read()
  read()
  io:close(myFile)
  read() //throws