← Back to context

Comment by anonymars

6 days ago

I think you are both unknowingly talking past each other: my understanding is that Smalltalk-style "object-oriented programming" ("everything is a message!") is quite distinct from C++/C#/Java/Rust "object-oriented programming" ("my structs have methods!")

Right, the former is what OOP is. The latter, encapsulating data in "objects", is functional programming.

  • They are both OOP, just as a "football" can be either spherical or oblong.

    Functional programming is not "encapsulating data in 'objects'". Such a model would naturally feature methods like "void Die.roll()", "void list.Add(element)" which are definitely not functional programming (which emphasizes immutability, pure functions, composition, etc.)

    • > They are both OOP, just as a "football" can be either spherical or oblong.

      They are both OOP like a football can be something that you use in a sport and something that flies you to the moon. Except it is not clear what flies you to the moon goes by "football".

      > Such a model would naturally feature methods like "void Die.roll()", "void list.Add(element)" which are definitely not functional programming

      Exactly, functional programming. `Die` and `list` encapsulate data and use higher order functions to operate on it, which is what defines functional programming.

      > which emphasizes [...] pure functions

      Functions without encapsulation is imperative programming. If you introduce encapsulation then, yes, you have functional programming, just like your examples above.

      Immutability is a disjoined property that can optionally apply to all of these programming paradigms. OOP, functional, and imperative programs can all be immutable, or not.

      Composition and encapsulation go hand in hand, so that one is also functional programming, yes. And certainly composition is core to languages like C++/Java/Rust/etc. Naturally, them being functional languages.

      To reiterate:

      - Imperative programming: Data and functions are separate.

      - Functional programming: Data is grouped with functions.

      - Object-oriented programming: Data is grouped with message responders.

      2 replies →