News for hackers. Stuff that matters.
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.