Re:Why care about functional programming? Part 1: Immutability
by ticking on Thursday March 19, 2015 @11:43PM
(#9236133)
Just do
nothing prevents you from reusing the variable name.
The point about immutability is that the objects themselves don't change.
[ Parent
| on HN ]
Re:Why care about functional programming? Part 1: Immutability
by taeric on Friday March 20, 2015 @12:29AM
(#9236223)
Alas, our style guide insists on final variables...
Re:Why care about functional programming? Part 1: Immutability
by the_af on Friday March 20, 2015 @12:51AM
(#9236283)
In my opinion, there is a reason for that. Consider the example above, slightly changed:
public foo(Bar bar) {
bar = baz(bar);
//Lots (10+ lines) of code.
bar = qux(bar);
//Lots (10+ lines) of code.
return finishProcess(bar);
}
It is hard to spot the second reuse of variable bar. This can make code harder to understand; it's a lot easier to just look at the point of definition of a variable and assume it never changes. At least, that is why I tend to use final when writing Java, and val when writing Scala.Of course, usually when adding final to messy Java code I'm trying to understand, this ends up telling me that the whole piece of code was fragile, hard to understand and in dire need of a refactoring. All of which makes final useful to me.