News for hackers. Stuff that matters.
Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @07:26AM (#27412366)
The article clearly shows that using the term OOP without further explanation is not helpful at all, rather confusing, because everyone has a different understanding.

Compare that the "functional programming" which in comparison has a glas clear definition, which makes it much easier to decide if some program is "pure functional" or not, avoiding prolonged and unproductive discussions.

Re:The Repeated Deaths of OOP (2015) by Rochus on Sunday June 06, 2021 @07:38AM (#27412427)
> "functional programming" which in comparison has a glas clear definition

Does it?

Re:The Repeated Deaths of OOP (2015) by ebingdom on Sunday June 06, 2021 @08:42AM (#27412764)
I would say it doesn't have a formal 100% unambiguous definition, but it's certainly _more_ well-defined than OOP: a functional programming language is one which is based on lambda calculus.
Re:The Repeated Deaths of OOP (2015) by Rochus on Sunday June 06, 2021 @08:49AM (#27412801)
Isn't every existing programming language eventually based on (or at least traceable to) lambda calculus? OOP is just another way to organize code.

Human language is unsuitable for "glass clear", unambiguous definitions, just because of its inherent fuzziness (which is nota bene an essential property for efficient communication).

Re:The Repeated Deaths of OOP (2015) by carapace on Sunday June 06, 2021 @03:09PM (#27415459)
> Isn't every existing programming language eventually based on (or at least traceable to) lambda calculus?

No.

Prolog et. al. is based on Horn Clause representation and evaluated using something called SLD resolution.

"Concatinative" languages (like Joy) are based on function composition (not application.)

(FWIW, the Turing machine is not based on Lambda calculus. Not that TMs are a programming language.)

Re:The Repeated Deaths of OOP (2015) by Rochus on Sunday June 06, 2021 @03:44PM (#27415704)
Aren't turing machines and the lambda calculus equivalent, i.e. each can efficiently simulate the other?
Re:The Repeated Deaths of OOP (2015) by carapace on Sunday June 06, 2021 @09:12PM (#27417951)
They're equivalent, but not identical. Lots of formal systems are Turing complete (e.g. Wang Tiles) and so can compute the same results as each other. Wolfram goes on about this some.

I sometimes wonder about the possible form of the "Platonic Ideal" is that each of these systems represent. George Spencer-Brown's Laws of Form seems to me to be the ultimate concrete example, but that's not a universally held opinion. :)

Re:The Repeated Deaths of OOP (2015) by Rochus on Monday June 07, 2021 @06:05AM (#27420801)
But doesn't that mean you can create a corresponding lambda calculus based version of a programming language, such as Landin did in his 1965 paper?
Re:The Repeated Deaths of OOP (2015) by carapace on Monday June 07, 2021 @12:33PM (#27424525)
Of course, but you could do that with the other formal systems too.

It's like Roman numerals vs. base-10 numerals, eh? "XXIII" and "23" both denote the same number (which may or may not exist depending on your metaphysical outlook) but neither notation can be said to be "the" notation.

Re:The Repeated Deaths of OOP (2015) by Rochus on Monday June 07, 2021 @02:06PM (#27425905)
That's ok; my concern was just whether "every existing programming language eventually based on (or at least traceable to) lambda calculus" responding to the fellow which claimed that "a functional programming language is one which is based on lambda calculus".
Re:The Repeated Deaths of OOP (2015) by ebingdom on Sunday June 06, 2021 @08:55AM (#27412836)
> Isn't every existing programming language eventually based on (or at least traceable to) lambda calculus?

Not really. FP has an obvious connection to lambda calculus. Many OOP languages don't even have a straightforward notion of "function", which is what lambda calculus is all about.

Re:The Repeated Deaths of OOP (2015) by Rochus on Sunday June 06, 2021 @11:01AM (#27413642)
> Not really

See e.g. Landin, P. J. (1965): A Correspondence between ALGOL 60 and Church's Lambda-notation.

Re:The Repeated Deaths of OOP (2015) by Rochus on Sunday June 06, 2021 @09:03AM (#27412869)
Re:The Repeated Deaths of OOP (2015) by ebingdom on Sunday June 06, 2021 @09:23AM (#27412992)
Yes, that's one of the most prominent in a long line of attempts at creating formal models of OOP. And in the preface, you'll find:

> There is a well-established theory of functions, the λ-calculus, ... However, our theory of objects is self-contained; it is the first that does not require explicit reference to functions or procedures.

So that answers your question in the negative and proves my point: no, not every language is based on lambda calculus.

Re:The Repeated Deaths of OOP (2015) by Rochus on Sunday June 06, 2021 @09:40AM (#27413074)
There are also different "schools of thought" for functional programming. That in itself is not a bad thing. The thread was about formal definitions; such are therefore available for those who need them.
Re:The Repeated Deaths of OOP (2015) by kaba0 on Sunday June 06, 2021 @01:52PM (#27414861)
How are expressions not based on lambda calculus in most “ordinary” languages? Yeah, they may side effect but at the same time lambda calculus itself is untyped, so is Haskell all that much closer to it over C++?
Re:The Repeated Deaths of OOP (2015) by tome on Sunday June 06, 2021 @02:02PM (#27414935)
Many other languages are not expression based at all. for loops cannot be considered "lambda calculus", for example (although of course there is a translation of them into a lambda calculus equivalent).
Re:The Repeated Deaths of OOP (2015) by kaba0 on Sunday June 06, 2021 @02:08PM (#27414992)
While they do have statements as well, they usually also have expressions, which are referentially transparent (and yeah I know it’s not the usage most people use, but it is the correct one: https://stackoverflow.com/questions/210835/what-is-referenti... ). (They don’t employ currying though)
Re:The Repeated Deaths of OOP (2015) by tome on Sunday June 06, 2021 @03:29PM (#27415609)
I never quite understood Uday's objection. Any language can be referentially transparent if you consider it's denotation to be just its syntax. Then you can always replace equals with equals, but the only thing equal to an expression is the exact same sequence of characters! The whole point is to be referentially transparent with respect to as coarse a semantics as possible. Haskell gets some of the way there, yet even

    let x = e
        y = e
    in ...
is not equivalent to

    let x = e
        y = x
    in ...
if your semantics can distinguish expressions by the time they take to evaluate.

Still (to address your original question) people do consider lambda calculi with effects, so if the expression-based fragment of an imperative language supports lambdas with lexical scoping then sure you could get away with saying that "their expression are based on lambda calculus".

Re:The Repeated Deaths of OOP (2015) by kaba0 on Sunday June 06, 2021 @03:51PM (#27415759)
I’m having a “debate” about it at another thread as well, so let me just point to a perhaps better explanation: https://elarib.com/item?id=22141647

So taking eg. Template Haskell, you actually loose referential transparency since then even the syntax itself matters and you can’t just replace it to an equivalent expression. I have no experience with Template Haskell itself so bare with me, but eg. having a macro m that converts the constant 2 to the string “two” while others to empty string will fail to be referentially transparent since `m 2` will not be the same as `let a = 2 in m a`.

Re:The Repeated Deaths of OOP (2015) by tome on Sunday June 06, 2021 @04:09PM (#27415890)
Firstly, I'm not sure you can even write that in Template Haskell. The syntax would actually be

    let a = 2 in $(m a)
and since `a` is not in scope at the time the TH splice runs compilation will fail. Secondly, even if you could write it, I don't really think something that contains Template Haskell should be called a "Haskell expression".

With regard to pron's comment, he has a long history of being technically correct with regard to Haskell. The operative point is

> What they mean is that the language is referentially transparent (like most language) and a term's reference (denotation) is an object value in the language

i.e. Haskell is referentially transparent with respect to a particularly coarse semantics (value semantics).

Anyway, your greater point that referential transparency doesn't imply immutability is completely correct.

Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @09:21AM (#27412976)
Yes, please see my other answer - it is much stricter/clearer defined than any OOP definition that I've seen.
Re:The Repeated Deaths of OOP (2015) by Zababa on Sunday June 06, 2021 @12:31PM (#27414217)
If I understood you correctly, you say that functional programming is what people usually call "pure fonctional programming"? If that's the case, the definition is better than OOP, but I don't think it's a property of functional programming but just that OOP is talked about more by more diverse people.
Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @07:14PM (#27417243)
Yeah - the term "functional programming" is nowadays as unclear as OOP. But "pure functional programming" is not - there is no equivalent in the OOP world.
Re:The Repeated Deaths of OOP (2015) by slver on Sunday June 06, 2021 @08:17AM (#27412637)
The funny thing is it's exactly the same thing with functional languages, and no, there's no clear definition of FP. Some FP is lazy, some isn't. Some is immutable, some isn't. Some claim it's a style in any language, others that it's a type of language.
Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @09:08AM (#27412898)
FP means that every expression (= part that can be evaluated) is referential transparent. Nowadays the word "functional" is used different from the original meaning (which some now call "pure functional")

> Some FP is lazy, some isn't.

The definition of FP implies that laziness is irrelevant. A language can enforce a pure functional style without being lazy or not.

> Some is immutable, some isn't

That's wrong. And it is a good example of why FP is much clearer defined. Referential transparency implies immutability. So there is no pure FP code that uses mutability.

> Some claim it's a style in any language, others that it's a type of language.

It's neither. It is a property of a program. Some languages enforce this property, others make it impossible to write a full program in this style. But that's independent of the definition itself.

I hope that explanation sheds a bit of light into it.

Re:The Repeated Deaths of OOP (2015) by kaba0 on Sunday June 06, 2021 @02:02PM (#27414932)
Sorry, it’s my pet peeve, but referential transparency doesn’t mean what many think it does — what you mean is simply side-effect freeness.

See the top answer here: https://stackoverflow.com/questions/210835/what-is-referenti...

Re:The Repeated Deaths of OOP (2015) by carapace on Sunday June 06, 2021 @03:20PM (#27415529)
That answer is so informative and yet it completely misses the point.

The problem is even called out in the answer itself:

> For example, our example "Edinburgh has been the capital of Scotland since 1999" signifies the fact that "capital of Scotland" depends on the time at which it is being considered. Such context-dependence is a reality, both in natural languages and programming languages.

"Therein lies the rub." Such context-dependence doesn't have to be a reality in programming languages. "2 + 2 = 4" is an eternal verity, not subject to context-dependence. The whole point of FP (going back to Backus' Turing Award paper where he introduces and defines "FP") is to operate in the pure realm of [binary Boolean] logic.

Re:The Repeated Deaths of OOP (2015) by kaba0 on Sunday June 06, 2021 @03:40PM (#27415670)
I agree with you, but this property of FP languages is called pureness/not-having side effects, not referential transparency.

The latter is (quoting pron’s older comment: https://elarib.com/item?id=22141647 ): “an expression e is referentially transparent if any sub-term in it can be replaced with any other having the same reference (aka denotation) without changing e's reference”. Perhaps I should have linked this comment over the stackoverflow answer, as it also mentions how eg. template haskell or LISPs are actually NOT necessarily referentially transparent due to macros. So while in Java replacing the constant 2 with a variable having value 2 is always equivalent (in reference, not necessarily effect!), the same may not be true with a given macro applied.

Re:The Repeated Deaths of OOP (2015) by carapace on Sunday June 06, 2021 @09:23PM (#27418015)
Fair enough. (I'm getting old, it hurts my head to imagine pure-but-not-referentially-transparent language; however, imagining referentially-transparent impure language doesn't.)
Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @07:19PM (#27417283)
Why are you so quickly assuming that you know better what I mean than I do?

Could you point out a specific point in my answer that is not compatible / or contradcits with the common definition of referential transparency?

Re:The Repeated Deaths of OOP (2015) by kaba0 on Monday June 07, 2021 @02:05AM (#27419511)
I didn’t mean to assume anything, I just wanted to note that the common definition used in FP circles is not correct. So just exchanging ref. transparency with “not having side effects” in your otherwise perfectly fine and interesting reply will make it correct — since for example Java is also referentially transparent which I guess you would not consider being a pure FP language. (Exchanging a value with a variable referring to the same value will not change the value denoted by the expression for example neither in Java, but it is not too interesting a property in itself)
Re:The Repeated Deaths of OOP (2015) by valenterry on Monday June 07, 2021 @02:51AM (#27419776)
Sorry, but I find your language inappropriate.

> what you mean is simply side-effect freeness

This really makes it sound like an assumption. And:

> So just exchanging ref. transparency with “not having side effects” in your otherwise perfectly fine and interesting reply will make it correct

You implying my answer is incorrect here but you are not giving an example of what is wrong even though I asked for it.

That being said, I believe that the definition of referential transparency (and therefore FP) is not useful at all without making "semantics" a part of it. And this is the point where discussion can happen. For example, is the performance characteristics of a function part of the program semantics? I would say no. Even though it matters in practice. Same goes for logging: one can argue that logging (that can not blow up due to e.g. lack of disk space) can be considered irrelevant for program semantics and hence a function that logs something with a "print" can still be pure.

If you remove semantics from the definition then the definition becomes rather useless imho. In that case I would rather change its meaning or switch to a different definition alltogether.

Re:The Repeated Deaths of OOP (2015) by kaba0 on Monday June 07, 2021 @03:09AM (#27419880)
I didn't want to repeat myself as the exact meaning was debated in two threads in this post already, for more details please have a look at them.

And I agree, we do have to specify what is the denotation of an expression that shall remain constant after replacing a sub-expression with that part's denotation -- for example choosing value of expression after evaluation is not too interesting, as it is shared by the majority of languages, and can only be "violated" by macros for example. Choosing the denotation as "value and side-effects" doesn't add much over saying simply that the language is pure and as you also note, purity has different levels.

Re:The Repeated Deaths of OOP (2015) by valenterry on Monday June 07, 2021 @04:01AM (#27420173)
If you do not point out any contradictions even after being asked twice then I have to conclude that you simply cannot. You could have also referred specifically or quoted the important lines from the other threads, but you did neither. That's not helpful in a discussion.

> Choosing the denotation as "value and side-effects" doesn't add much over saying simply that the language is pure

You are aware that, regarding the discussion between us two, it was you and not me who even used the term "side-effect" first, right?

Re:The Repeated Deaths of OOP (2015) by kaba0 on Monday June 07, 2021 @04:58AM (#27420467)
https://news.ycombinator.com/item?id=27415670

https://news.ycombinator.com/item?id=27414992

> FP means that every expression (= part that can be evaluated) is referential transparent

> Referential transparency implies immutability

Both of these statements are false. As I said, Java is referentially transparent.

addOne(2)’s value is the same as the value of the last line in `var a = 2; addOne(a)`. And Java is most definitely not a pure FP language, and its referential transparency doesn’t imply immutability. You can argue that inserting `int two() { sideEffect(); return 2; }` ‘s invocation in place of 2 will change the semantics of the program but that is precisely the meaning of a side-effecting function — so using referential transparency is redundant in that meaning.

Re:The Repeated Deaths of OOP (2015) by valenterry on Monday June 07, 2021 @06:31AM (#27420967)
Thank you for explicitly pointing it out.

I disagree with you - I think you are using a different definition and there seems indeed to be discussion about what the definition really is. Wikipedia for examples uses the definition that I use, but in the Talk-section someone made a similar complaint to yours (or was that you :)). [https://en.wikipedia.org/wiki/Referential_transparency]

I stick to my definition though, because... I find it more useful and I think it is the more common one.

Re:The Repeated Deaths of OOP (2015) by pflanze on Sunday June 06, 2021 @10:00AM (#27413207)
> FP means that every expression (= part that can be evaluated) is referential transparent.

Most real-world programming requires handling of side effects somewhere, so such programs have parts which are not referentially transparent.

It's why I distinguished between "core" and "meat" in my other response. Functional programming languages offer features that help making a larger part of the program referentially transparent (and, optionally, to ensure that property in the types).

> Nowadays the word "functional" is used different from the original meaning (which some now call "pure functional")

I don't think the meaning changed, just the tools offered and the scope of the support they offer to achieve referential transparency (pure functions). Early Lisp offered expression oriented programming which was a step towards it, but used dynamic scoping which isn't really helping. Later on both Lisps and ML offered lexical scoping. Then the purely functional trend came up via Miranda and (Clean and) Haskell, the latter encoding purity in the type system. In the last decade mainstream programming languages added functional programming features but are falling short in encoding purity in the types (just as Lisp never did), which means that it's (easily) possible for the abstractions offered (both functions but also libraries built on iterators) to not be referentially transparent, manual care (and/or culture) is required instead. The tooling doesn't help enough to guarantee referential transparency. But the core idea, the target of the efforts, is the same.

> Referential transparency implies immutability.

I didn't go into immutability in my other response because you can use mutation inside pure functions, as long as the effect doesn't leave the function. Building referentially transparent functions does not imply using immutable data structures or variable bindings inside.

Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @10:27AM (#27413403)
> Most real-world programming requires handling of side effects somewhere, so such programs have parts which are not referentially transparent.

That's not correct though. Look at Haskell (or even stricter Idris). This is real world application code that can do whatever Java, C++, ... can do, but it is pure functional and hence doesn't contain any non referentially transparent parts. Just because an application is written in a pure functional style does not mean that it cannot e.g. write into a database when it is executed.

Of course many languages don't even allow to use a fully pure functional style. In that case, a more or less big functional "core" is the closest one can come to a pure FP style.

> I didn't go into immutability in my other response because you can use mutation inside pure functions, as long as the effect doesn't leave the function.

Sure you can do that and sometimes it is even the best practical solution. And the function might even be referential transparent - but your whole application is now not pure functional anymore, because a part of it is not referential transparent anymore.

Hence: if an application has to satisfy the criteria of being "pure functional" then every expression must be referential transparent and hence no mutation can be used.

Re:The Repeated Deaths of OOP (2015) by pflanze on Sunday June 06, 2021 @11:04AM (#27413677)
It's funny that you defend your view using Haskell, as I was replying with Haskell in mind.

If you use the state monad, you encode local side effects. Then you use runState in a function that has a non-monadic type--a pure function.

Feel free to argue that the state monad is only having pure expressions because it can be represented using only pure functions and partial evaluation. For all practical purposes it is used to write code that exerts (local) side effects into the state maintained by the state monad.

You can a function in say, OCaml, that fills an array via mutation using only function arguments to deduct the contents, and then returns that array. That function is pure (it exerts no side effects outside and is not exposed to side effects from the outside, its result value only depends on the function argument values). Yet how is that not using mutation, non-referentially transparent parts inside?

You can write the same function with a mutable vector in Haskell (Data.Vector.Mutable, using the ST monad). How is it not exactly the same code as the one in OCaml except for the types that guarantee the purity? Yes, it may be using pure expressions underneath to guide the type system to enable the proof of purity. But does that change what I said? Both to the programmer and (after optimization) to the machine the code is using mutation. You can model mutation using only pure functions. That may be useful in some ways, but you can also take a C program, represent every memory address as an entry in a tree of immutable nodes, the outside world as an abstract entity with versions, and recreate it with only pure expressions. That may be what is useful in some contexts for developing proofs or to implement type systems, but is this relevant for a programmer interested in writing more functional programs? Why not just say that using ST is using local mutation (that the type system can guarantee will not leak outside) and be done with it?

Re:The Repeated Deaths of OOP (2015) by tome on Sunday June 06, 2021 @12:46PM (#27414357)
Equivocation about purity, referential transparency, mutability, side effects etc. is not very interesting. The operative point is that, in Haskell, firstly

    x = expression
    y = expression
    ...
is the same as

    x = expression
    y = x
    ...
and that, secondly

    x = expression
    ...
is the same as

    ...
when x does not appear in ... . Those are the important properties of Haskell (with regard to this discussion). Whether this advances the discussion is another matter ...
Re:The Repeated Deaths of OOP (2015) by slver on Sunday June 06, 2021 @02:07PM (#27414975)
I'm not deep into Haskell, but isn't the interpreter monad pattern effectively a language within the language that acts in a very conventional procedural way for interacting with IO and other external concerns? I just wonder... does Haskell really need syntactic segregation for this, and how is that better than any language which can declare/enforce pure functions/modules without the entire language being like that by default.
Re:The Repeated Deaths of OOP (2015) by tome on Sunday June 06, 2021 @03:21PM (#27415532)
Well, give it a go! Or alternatively, look for languages that have been successful in enforcing any kind of purity and that also permit unrestricted use of higher order functions.
Re:The Repeated Deaths of OOP (2015) by slver on Sunday June 06, 2021 @06:05PM (#27416791)
It's very hard to make Haskell look attractive to me, I deal with open systems (i.e. systems which interact with many other heterogenous systems which evolve in time), and Haskell is optimized for precisely the opposite case (a walled garden built out of elaborate types for verifying correctness). Haskell is the weird introvert guy in an extrovert world.
Re:The Repeated Deaths of OOP (2015) by valenterry on Monday June 07, 2021 @04:53AM (#27420444)
Interesting - for me it is the opposite. Non-functional languages usually work better if there is no concurrency involved. And 3rd party systems always introduce a certain amount of concurrency, sometimes more, sometimes less.

I would say pure FP languages such as Haskell are actually the best for such a case. Because in these languages the order/timing of lines of code are decoupled from the execution order/timing.

Re:The Repeated Deaths of OOP (2015) by slver on Monday June 07, 2021 @11:33AM (#27423778)
> I would say pure FP languages such as Haskell are actually the best for such a case. Because in these languages the order/timing of lines of code are decoupled from the execution order/timing.

... That's good in your opinion?

Re:The Repeated Deaths of OOP (2015) by valenterry on Monday June 07, 2021 @08:18PM (#27429095)
If your program is simple and LoC are executed one by one and that is totally fine, then FP just takes away the natural relation between LoC and execution and adds another layer of unnecessary complexity.

But when the percentage of concurrent code grows bigger, then it is better - because you lose the LoC<->execution relation anyways.

You can for example see that in Python. Python makes it really hard to break out of that model and have a line of code running while another one is running. That's why paralle and async/concurrent programming is such a PITA in python.

So, in my opinion for some problems the FP style is much better, because instead of "working your way around", you embrace the fact that LoC and execution are inherently decoupled.

Re:The Repeated Deaths of OOP (2015) by tome on Monday June 07, 2021 @06:13AM (#27420844)
Hmm, not really. See, for example, Clash, a Haskell compiler for synthesising hardware circuits, or Cardano, a massively distributed software system realising a cryptocurrency.
Re:The Repeated Deaths of OOP (2015) by pflanze on Monday June 07, 2021 @10:43AM (#27423191)
> Equivocation about purity, referential transparency, mutability, side effects etc. is not very interesting.

It's what the current discussion is about, since I explained why I explicitly didn't make a statement about immutability being required for FP.

> The operative point is that, in Haskell, firstly

> x = expression

> y = expression

> ...

> is the same as

> x = expression

> y = x

> ...

Sure but that's the pure part of a program.

    x <- expression
    y <- expression
is not generally the same as

    x <- expression
    let y = x in ...
and I pointed out that you can have such a program (i.e. with mutability) inside a function that is pure to the outside.

The interesting feature of Haskell / Monads is that you can have mutability be both inside and around pure expressions (impure code making use of pure code and then impure code again inside the implementation of pure code). Not everything in a Haskell program needs to be pure. Of course, pure expressions are good since they are easier to reason about. Also, they are the core idea of FP as I mentioned earlier. But, I want to avoid people taking away the impression that you then never can use mutable data structures, and that's why in my original comment I didn't make a statement about immutability being required for functional programming.

Functional programming has a core idea and that is pure expressions (referential transparency), and then features to help increase the area of programs which are pure expressions and increase the confidence / safety of them being so. With regards to that confidence, Haskell goes far (there's still unsafePerformIO (and non-total functions) so it's not completely perfect). And I'm not disputing that when I say that it still is and always was called functional programming when there were no language-provided features to give that confidence, or only "half-assed" ones if one wants to call them that. Or only culture and convention. My point in the whole discussion is to explain why functional programming doesn't mean the same thing for everyone, and how it can both be that @slver says "there's no clear definition of FP" and that there is at the same time. There is a clear definition for referential transparency, which is the core idea of FP. But the term FP also encompasses various approaches and tools with varying qualities to enable that core idea, and it's here where there's no clear definition.

Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @07:29PM (#27417351)
> For all practical purposes it is used to write code that exerts (local) side effects into the state maintained by the state monad.

Yes, but as long as this is done with only pure expressions, then the whole program is pure functional - that is what the definition is about.

> You can a function in say, OCaml, that fills an array via mutation using only function arguments to deduct the contents, and then returns that array. That function is pure (it exerts no side effects outside and is not exposed to side effects from the outside, its result value only depends on the function argument values). Yet how is that not using mutation, non-referentially transparent parts inside?

The guarantee or at least convention of referential transparency for every expression has benefits. It means I as a developer can make certain assumptions about code that I could not make otherwise. I can do certain refactorings and changes while being sure that it will not change the program semantics.

As soon as parts of the program is not pure anymore, I know have to always re-assure myself that I'm currently working with the pure part of the code. Same for any tooling that I build.

As I said, you can make that choice and sometimes it is the best thing to do - but you cannot call your application "pure functional" anymore when you do.

Re:The Repeated Deaths of OOP (2015) by slver on Sunday June 06, 2021 @11:34AM (#27413835)
> > Some is immutable, some isn't

> That's wrong. And it is a good example of why FP is much clearer defined.

OCaml and F# are two examples of functional languages with freely supported mutable data types. So maybe what I said is "wrong" about your personal idea of what FP is.

But it's clearly not "wrong" about the fact some people see immutability as optional for FP, which is the very point I'm making.

Re:The Repeated Deaths of OOP (2015) by ratww on Sunday June 06, 2021 @02:51PM (#27415309)
> OCaml and F# are two examples of functional languages

Both OCaml and F# are multi-paradigm languages that have FP features, but are not restricted to FP. The support for mutability comes from their imperative/OOP ancestors, not from FP.

Re:The Repeated Deaths of OOP (2015) by pflanze on Sunday June 06, 2021 @08:50AM (#27412809)
AFAICT the core of FP is referential transparency. The "meat" of FP are the tools available which allow to (comfortably) increase the portion of the program that is referentially transparent.

Immutability, first class functions, laziness are all such tools. And which tools are used can vary, just like the tools that help "doing OO" can vary.

But I think that FP does have that core which has a glass clear definition. I'm not sure which is the core of OO. Maybe it's the idea of "encapsulating" mutation (basically inverting the core of FP). Maybe it's the principle of virtual methods / messaging. It's not so clear I think.

Re:The Repeated Deaths of OOP (2015) by ebingdom on Sunday June 06, 2021 @08:47AM (#27412786)
It's true that functional programming also doesn't have a formal definition, but I wouldn't say it's "exactly the same" as with OOP. Functional programming is based on a simple well-understood mathematical model: lambda calculus. While there are different flavors of lambda calculus, they are related in obvious ways and one can reach formal conclusions them as a whole, e.g., the Church-Rosser theorem. In contrast, the many attempts to formalize the essence of OOP have resulted in countless wildly different results, so it's impossible to say anything meaningful about OOP, with the possible exception of this sentence.
Re:The Repeated Deaths of OOP (2015) by ebingdom on Sunday June 06, 2021 @09:30AM (#27413017)
To all the people downvoting me: if you really think OOP is as well understood as FP, learn some programming language theory. Tell me what the universally agreed foundation of OOP is. You won't be able to, but I can tell for FP it's lambda calculus.
Re:The Repeated Deaths of OOP (2015) by slver on Sunday June 06, 2021 @11:57AM (#27413997)
> Tell me what the universally agreed foundation of OOP is.

I'll deliberately avoid terms so we don't get to argue about words, but rather substance.

1. Objects have identity that's independent of their state (two objects with same state are still distinct).

2. Objects contain implementation which is hidden, including optionally mutable state.

3. Communication occurs through handlers/methods/calls, which provide only INDIRECT access to the object's internal state.

4. Objects can stand for one another, if their handlers react in a compatible way with the object they're replacing.

I tried to keep it as basic as possible, while avoiding topics about inheritance and what not.

Now the question is "do you need an OOP language to do OOP", and no, you don't. There's overlap. For example if you take the above, you'll notice that closures in FP match all of those except one thing: mutable state. So if your FP language allows mutable state, then you can do OOP in it with closures. And that's not a proof that OOP is not a thing, rather it's a proof that what some small minds keep putting in opposition, things like FP vs OOP vs DOP are just pieces of a larger puzzle that forms a single cohesive picture.

Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @07:32PM (#27417363)
Doesn't 4 contradict 1? Or do you mean "can stand for one another in a certain context". That would be rather weak criteria then though.
Re:The Repeated Deaths of OOP (2015) by slver on Monday June 07, 2021 @07:41AM (#27421383)
1 is about object identity. 4 is about object type/function. I.e. polymorphism.

It may seem like a weak criteria if you're using to OOP/FP languages that provide typesafe, efficient polymorphism out of the box. But the reason we have Obj C and C++ is that polymorphism (while also maintaining encapsulation etc.) is a living nightmare in a language like C.

Re:The Repeated Deaths of OOP (2015) by jasperry on Sunday June 06, 2021 @10:53AM (#27413596)
I agree that functional programming has a more widely agreed-upon foundational set of definitions than OOP. However, it doesn't follow from that that "it's impossible to say anything meaningful about OOP".
Re:The Repeated Deaths of OOP (2015) by jtdev on Sunday June 06, 2021 @08:41AM (#27412760)
FP is a cult.
Re:The Repeated Deaths of OOP (2015) by ebingdom on Sunday June 06, 2021 @08:52AM (#27412821)
> FP is a cult.

It's a programming paradigm based on simple, well-understood mathematical framework. It's also the starting point for most research in programming language theory.

Re:The Repeated Deaths of OOP (2015) by jtdev on Sunday June 06, 2021 @09:02AM (#27412862)
Explain why closures are allowed to mutate state in this “simple, well understood” framework.
Re:The Repeated Deaths of OOP (2015) by pflanze on Sunday June 06, 2021 @10:15AM (#27413312)
Whether closures are or are not allowed to mutate state depends on the programming language (or the aim of the programmer, if the programming language doesn't force their way). Closures are a syntactical building block helping functional programming (building functions out of objects is just much more syntactical overhead), but whether a particular closure is a pure function or not is a separate concern. If the function is to be pure (hence satisfying the core of the "framework") then it would not be allowed to mutate state.
Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @09:19AM (#27412963)
They are not allowed to. Why do you think they are?
Re:The Repeated Deaths of OOP (2015) by jtdev on Sunday June 06, 2021 @10:08AM (#27413265)
From the Swift docs regarding closures (I would have used Haskell doc reference, but the Haskell docs are so esoteric and vague as to be nearly useless):

“A closure can capture constants and variables from the surrounding context in which it’s defined. The closure can then refer to and modify the values of those constants and variables from within its body, even if the original scope that defined the constants and variables no longer exists.”

https://docs.swift.org/swift-book/LanguageGuide/Closures.htm...

Re:The Repeated Deaths of OOP (2015) by ebingdom on Sunday June 06, 2021 @10:29AM (#27413421)
> From the Swift docs regarding closures

What makes you think Swift only supports functional programming?

> I would have used Haskell doc reference

And if you would have, you would have disproved your own point. In Haskell, closures cannot mutate state, because mutable state is not part of the language semantics. It's modeled explicitly via monads.

Re:The Repeated Deaths of OOP (2015) by valenterry on Sunday June 06, 2021 @10:29AM (#27413416)
Swift is not a language that enforces code to be pure functional though.
Re:The Repeated Deaths of OOP (2015) by jtdev on Sunday June 06, 2021 @04:20PM (#27415975)
FP = debating largely academic nuances that have almost zero material effect on software deliverables, purely for ego driven reasons.