Re:Classes are a way of writing higher order functions
by flowerlad on Wednesday September 09, 2020 @02:39PM
(#24424235)
I don't see parallels between OOP and retained mode, and functional and immediate mode the way you are describing. UI components inherently have state. Pretending they can programmed in functional style with stateless functions is bizarre because UI functions do have side effects. See prior discussion: https://news.ycombinator.com/item?id=24363261
Re:Classes are a way of writing higher order functions
by lukevp on Wednesday September 09, 2020 @04:24PM
(#24425519)
Yes, ui components have state in the case of a retained mode GUI like the DOM, but in the case of React, relevant data is derived from the application state (eg IsDarkMode is a state property used to derive colors for a component, or the checked state of a checkbox) and a unidirectional flow propagates that state change to the VDOM on every re render. Functional doesn’t mean stateless (state exists as closures within higher order functions, such as in the composition of functional components within React), it means side-effect-free, it means determinism in the derivation of additional state based on immutable state updates.
Re:Classes are a way of writing higher order functions
by flowerlad on Wednesday September 09, 2020 @05:57PM
(#24426401)
> Functional doesn’t mean stateless (state exists as closures within higher order functions, such as in the composition of functional components within React)
Being stateless and side-effect free is pretty fundamental to functional programming. If you can't replace a function call with its resulting value (without changing the meaning of the program) then it is not functional programming.
React is neither stateless nor side-effect free. Mapping it to concepts from functional programming is counter-productive. You get something that is neither fish nor fowl.
Re:Classes are a way of writing higher order functions
by pjmlp on Wednesday September 09, 2020 @01:44PM
(#24423636)
Not all OOP languages support inheritance, nor all FP languages are immutable by default, though.
GUI programming surely wasn't retained-mode on 16 bit home computers, in fact that was one of the issues getting used to GUI based OSes event queues back in the day.
GUI programming is traditionally retained-mode. OOP is traditionally state encapsulation and mutability. OOP and retained-mode GUIs are conceptually similar, and Functional Programming and immediate-mode GUIs are conceptually similar.
Here's a good explanation of this: https://medium.com/@puppybits/immediate-mode-reactjs-7a6302c...