Dec. 8th, 2012

davv: The bluegreen quadruped. (Default)
Where others would watch junk TV, I watch let's plays of FTL. (Or I did, lately)

I don't know why, but it's something I can just watch and not think about too much :) Even though it's a very weird thing to be watching, given that I don't even own the game.
davv: (Seemingly) technical contradiction (Code)
And I think I see another reason for "everything is a reference", now. It's due to inheriting from functional programming.

In functional programming, particularly in pure functional programming, when you pass a parameter, you're passing that parameter, not a copy of it. For instance, in mathematics, when you say f(3, 4) = 7, then you're dealing with that particular 3 and that particular 4, not copies of them. And if the function is pure (doesn't have side effects), there's no advantage to making copies since the parameters aren't going to be altered anyway.

Thus, in functional programming, the default is to use "references" (or rather, use the actual things that are passed into the function rather than copies of them). And if the modern languages are trying to take a little from functional, a little from OO, a little here and there, it's not that surprising they'd crib "acts upon the object itself rather than a copy of it" from functional.

The problem, of course, arises when functional parameters are supposed to be immutable but the modern languages have mutable objects by default. Then the encapsulation trickery shows up, and you have to be aware that f(x) isn't covertly tinkering with x (or that you can't use something returned by someObject.getFoo() to alter a private inside someObject), or you get a nasty surprise.

It might be a reason they adopted everything-is-a-reference. I don't think that's the reason Java did it, but for the more modern languages, might very well be.

March 2018

S M T W T F S
    123
45678910
1112131415 1617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 30th, 2025 01:13 pm
Powered by Dreamwidth Studios