by WHoWHo · 8y ago · 0 comments
Person p = ....
p = doSomething(p)
...
p = doSomethingElse(p)
is hard to reason about when it should be Person p = ....
... lots of code
Person updated = doSomething(p)
... lots of code
doSomethingElse(updated)
Which is easier to read and understand. So you might have had bugs that would have been prevented with final, but you didn't attribute to final.You shouldn't be able to doSomethingElse(p) when you actually mean to doSomethingElse(updated).
What would help is splitting the function up so that you don't have multiple named variables representing multiple versions of the same thing in the same scope:
Person doSomethingAndDots() {
Person p = doSomething(...)
...
return p
}
main() {
doSomethingElse(doSomethingAndDots())
}That is to ease the pain of unwrapping nested types and error-checking intermediate steps so you don't have to come up with new names for each intermediate.