Live data from Hacker News

What's functional programming all about? (2017)

lihaoyi.com

31–40 of 158 posts

Re: What's functional programming all about? (2017)

#31
post #25

Earlier quoted context omitted.

In most OO languages, message passing is just a fancy term for function calling. It’s really not fundamentally different from functional application on a closure value in FP. OOP is defined by encapsulation and subtyping (polymorphism and inheritance). In fact, the one thing that doesn’t exist in standard FP is inheritance. (Encapsulation sort-of exists with closures, and polymorphism exists with function values.)

> In most OO languages, message passing is just a fancy term for function calling. Having objects does not make a language oriented to those objects. By your definition C++ would be considered OO, but we know it is not. Kay quite explicitly stated that C++ is not OO. I expect you're thinking of Object- based programming. If you look at the actual definition of OO, it basically is just a laundry list of Smalltalk feat…

I don’t really care much about what Kay says. His view of OO isn’t what caught on. C++ as a descendant of Simula, which is considered the first object-oriented programming language, certainly supports OO. (C++ is really a multi-paradigm language.)

Object-based means OO without inheritance or subtyping.

Re: What's functional programming all about? (2017)

#32
post #31

Earlier quoted context omitted.

> In most OO languages, message passing is just a fancy term for function calling. Having objects does not make a language oriented to those objects. By your definition C++ would be considered OO, but we know it is not. Kay quite explicitly stated that C++ is not OO. I expect you're thinking of Object- based programming. If you look at the actual definition of OO, it basically is just a laundry list of Smalltalk feat…

I don’t really care much about what Kay says. His view of OO isn’t what caught on. C++ as a descendant of Simula, which is considered the first object-oriented programming language, certainly supports OO. (C++ is really a multi-paradigm language.) Object-based means OO without inheritance or subtyping.

Simula long predates OO. To call it an OO language is laughable.

Simula has objects, but that does not imply that the objects are oriented.

Re: What's functional programming all about? (2017)

#33
post #31

Earlier quoted context omitted.

I don’t really care much about what Kay says. His view of OO isn’t what caught on. C++ as a descendant of Simula, which is considered the first object-oriented programming language, certainly supports OO. (C++ is really a multi-paradigm language.) Object-based means OO without inheritance or subtyping.

Simula long predates OO. To call it an OO language is laughable. Simula has objects, but that does not imply that the objects are oriented.

[deleted]

Re: What's functional programming all about? (2017)

#35
As a programmer, I don't know if it's still relevant to make a strict separation between programming paradigms. You can use immutable types, pure functions, closures and so on in most languages. Conversely, you can define mutable types and imperative code in most functional programming languages.

I'm always surprised reading comments on these topics, people saying they don't grasp FP. But don't we use higher-order functions, closures, combinators all the time in most mainstream languages? How hard can it be to learn OCaml or Clojure for someone who use closures all over the place in JS?

Monads have a steeper learning curve, but besides Haskell, they aren't that pervasive. And there are constructs with similar flavor in mainstream languages too (result types in Rust...)

Re: What's functional programming all about? (2017)

#36
post #31

Earlier quoted context omitted.

I don’t really care much about what Kay says. His view of OO isn’t what caught on. C++ as a descendant of Simula, which is considered the first object-oriented programming language, certainly supports OO. (C++ is really a multi-paradigm language.) Object-based means OO without inheritance or subtyping.

Simula long predates OO. To call it an OO language is laughable. Simula has objects, but that does not imply that the objects are oriented.

The inventors of Simula disagree: http://kristennygaard.org/FORSKNINGSDOK_MAPPE/F_OO_start.htm...

Re: What's functional programming all about? (2017)

#37

As a programmer, I don't know if it's still relevant to make a strict separation between programming paradigms. You can use immutable types, pure functions, closures and so on in most languages. Conversely, you can define mutable types and imperative code in most functional programming languages. I'm always surprised reading comments on these topics, people saying they don't grasp FP. But don't we use higher-order fu…

Monads are pervasive: async-await.

We just don’t call them monads.

Re: What's functional programming all about? (2017)

#38
post #36

Earlier quoted context omitted.

Simula long predates OO. To call it an OO language is laughable. Simula has objects, but that does not imply that the objects are oriented.

The inventors of Simula disagree: http://kristennygaard.org/FORSKNINGSDOK_MAPPE/F_OO_start.htm...

Implying that the inventors of Simula had a time machine?

I am inclined to think the more logical explanation is that they didn't actually take OO back in time and that Simula isn't an OO language at all (perhaps confused by the first OO language being created with Simula?), but admittedly I'm rooting for the time machine! Look forward to you telling us more about it.

Re: What's functional programming all about? (2017)

#39

The article itself was well written, although I'd appreciate if the author was more "to the point" with the examples. FP never resonated with me and never fit the mental model I have for programming. I tried learning Prolog and Haskell a few times, and I never felt like I could reason about the code. This line from the article: "[..] With functional programming, whether in a typed language or not, it tends to be much…

I’ve wondered for some time how this breaks down along preferences for math vs (human) language, or for proofs/formula thinking vs algorithmic. I find FP concepts easy enough to grasp (provided they’re not demonstrated in e.g. Haskell) and even adjacent stuff like typeclasses or monads or what have you aren't a stumbling block, and I'm plenty comfortable with stuff like recursion. … but I'm firmly on the language-is-…

the "FP is for math people" meme IMO is incorrect and comes from FP mainly being used to refer to Pure FP, aka Haskell.

While Monads and co. are interesting constructs, I think the main thing with FP (pure or not) is immutability by default.

That alone makes code so much easier to think about, in my experience.

One can do FP in languages not commonly associated with FP by just not (re)assigning variables. FP languages just make it increasingly hard to do so.

Re: What's functional programming all about? (2017)

#40
The classic dichotomy drawn between functional programming (FP) and object-oriented programming is the "Expression Problem" [0]; in the former approach you optimize for extensibility of the number of operations in your model, at the cost of reduced developer ergonomics when attempting to extend the number of types you can operate upon. In the latter, object-oriented approach, you have the inverse tradeoff.

In FP the fundamental unit of composition is the function; your solution is expressed as a composition of functions, which are treated as first-class objects (first-class meaning, functions can be manipulated via higher-order functions, or "functions of functions"), a feature not always seen in object-oriented or multi-paradigm languages. Polymorphism is most frequently achieved through parametric polymorphism, or "generics," and ad-hoc polymorphism, or "trait bounds"/"typeclass constraints".

In OOP the fundamental unit of composition is the object; your solution is expressed as a composition of objects, whether through actual composition/aggregation (objects containing and possibly delegating to other objects [1]), or subtype polymorphism, also known as "inheritance." Parametric and ad-hoc polymorphism can often feature in OOP languages as well, but subtype polymorphism is a distinguishing characteristic of OOP.

Functions, particularly pure functions without side effects in the "real world" such as I/O or hardware access, are akin to equations in which an expression can be replaced by its value - the "left-hand side" equals the "right-hand side." Mutable state often does not enter into the picture, especially when programming in this "pure" (side-effect free) style. This makes functional programs easier to reason about equationally, as one can determine the value of an expression simply by inspection of whatever variables are in the function's scope, without having to keep track of the state of the entire program.

Objects are distinguished by their often stateful nature as they bundle together data/internal state, and operations over that internal state. Often such internal state is hidden or "encapsulated" from the client, and the internal state is only modifiable (if at all) via the object's class' set of public methods/operations. Objects with immutable internal state are more akin to closures from functional programming - that is, functions with access to a "parent lexical scope" or "environment."

Between the two extremes exists an entire spectrum of mixed-paradigm languages that incorporate features of both approaches to structuring and modelling a software solution.

[0] https://wiki.c2.com/?ExpressionProblem

[1] https://en.wikipedia.org/wiki/Composition_over_inheritance

Post reply on HN