Are FP and OO orthogonal?

后端 未结 10 1563
-上瘾入骨i
-上瘾入骨i 2020-12-12 10:51

I have heard this time and again, and I am trying to understand and validate the idea that FP and OO are orthogonal.

First of all, what does it mean for 2 concepts t

10条回答
  •  攒了一身酷
    2020-12-12 11:54

    First of all, what does it mean for 2 concepts to be orthogonal?

    It means they don't affect each other. I.e. a functional language isn't less functional because it's also object oriented.

    They seem like opposites. How does it affect their orthogonality?

    If they were opposites (i.e. a purely functional language could not possibly be object oriented), they would by definition not be orthogonal. However I do not believe that this is the case.

    and OO seems like something that is built for state and mutation(a slightly organized version of imperative programming?). And I do realize that objects can be immutable. But OO seems to imply state/change to me.

    While this is true for most mainstream OO languages, there is no reason that an OO language needs to have mutable state.

    If a language has objects, methods, virtual inheritance and ad-hoc polymorphism, it's an object oriented language - whether it also has mutable state or not.

提交回复
热议问题