4 ms·
Non-functional languages seem to pay lip service to FP, confusing people into thinking they're already using it. Example: It is well known that "Java Strings a
by mrkeen 8y ago
Non-functional languages seem to pay lip service to FP, confusing people into thinking they're already using it.
Example:
It is well known that "Java Strings are immutable", which is a good idea. Yet you can absolutely write:
> String str = "hello,";
> str += "world!";
So it's "immutable" for some lawyerish definition which does me no good. If I write a method that depends on s, it will produce different results each time.
> So functional programming should never handle state
Not at all. You should know (and be able to enforce) when your code does mutations.
- kbp 8y ago> Yet you can absolutely write: > String str = "hello,"; > str += "world!"; So it's "immutable" for some lawyerish definition which does me no good. `str` is a mutable reference to an immutable object. You can make the reference point to something else, but the object being pointed to is immutable, so eg if you pass it to a function, that function cannot change it under you. If you want to make the reference immutable, declare it as final. I don't think understanding the difference between a pointer and the value it points to is lawyerish.
- mrkeen 8y agoThank you. ^ that's the lawyerish definition I was referring to ^
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- jhomedall 8y agoStrings are immutable. Variables can be reassigned. Those are two very different things. Strings being immutable means that you can can pass around references to them, safe in the knowledge that they can't be modified. For example: void example() { String s = "hello"; someOtherMethod(s); // `s` is guaranteed to still be "hello" here. } Or, a live example using repl.it: https://repl.it/repls/BothTrivialQuadrant https://repl.it/repls/BothTrivialQuadrant