Campbell Ritchie wrote:How does labelling local variables final make code difficult to read?
I have come across a file having more than 2000 lines.
Ernest Friedman-Hill wrote:I would argue that the opposite is true: final variables make code considerably easier to read. If you know that a variable will never be changed, then you can make a lot of assumptions about it while you read.
David Newton wrote:How does making local variables final make it easier to make code more OO?
Campbell Ritchie wrote:How does labelling local variables final make code difficult to read?
Ulf Dittmer wrote:
I have come across a file having more than 2000 lines.
Ouch! I'd say once a class goes beyond a couple hundred lines of code or so, it is time to start refactoring.
hemant Budhewar BamniBk wrote:Can anybody read such code quickly, so that development becomes fast.
I don't think so.
hemant Budhewar BamniBk wrote:If it is so then, why this Check style rule is not applied in sun's standard classes, or any other software code?
hemant Budhewar BamniBk wrote:My main aim is to know how much this rule is beneficial for code quality.
Mike Simmons wrote:
If it's something unusual to you, you spend time wondering "why is this variable final?" and it slows you down.
hemant Budhewar BamniBk wrote:
Well, Sun's style was developed long ago, whereas a preference for immutability is something that's becoming popular more recently. I wouldn't expect Sun to go back an insert final in a bunch of old code. It is a good question why we don't see this style used more for new projects and organizations.
hemant Budhewar BamniBk wrote:
In my opinion, it's beneficial, but only marginally. So there's not a big compulsion to convince others to do it. Further, it's most beneficial if you have long methods - and I am pretty aggressive about making my methods as short as possible. For people who keep their methods short, it doesn't matter very much whether the local variables are final - the shortness makes it easy to see what happens to the variable. And I think short methods are much more important than final local variables.
hemant Budhewar BamniBk wrote:
On the other hand, I do aggressively apply final to any field that I can. And there are many others out there who do the same. That's much more beneficial, because fields generally stick around much longer than local variables. So simplifying their behavior has a bigger impact on understandability. And of course it's very helpful for multithreaded code. That's not what this thread is about, of course, but I thought it worth clarifying.
Ulf Dittmer wrote:
I have come across a file having more than 2000 lines.
Ouch! I'd say once a class goes beyond a couple hundred lines of code or so, it is time to start refactoring.
hemant Budhewar BamniBk wrote:What about if the development is already done and if it has more regression in refactoring the complex code?
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:
hemant Budhewar BamniBk wrote:What about if the development is already done and if it has more regression in refactoring the complex code?
If development is completely done and you aren't getting enhancement requests, why are you sitting there adding the final keyword? Seriously, I refactor code I am going to touch. Or code with a bigger problem that we have agreed to refactor after release. I don't just go randomly changing code.
As for final, I use it in new code inconsistently. I mainly use it when I want to make it clear that a local variable shouldn't change. Not when it just happens to not change. I never use final in method parameters because I have another static analysis rule that flags when a method parameter gets set. That rule is higher severity than the one to use the final keyword. And of course I do use final for class level constants.
I also think that new methods should be written smaller so there aren't so many variables present. Making the benefit of this less important.
Jeanne Boyarsky wrote:
I have another static analysis rule that flags when a method parameter gets set. That rule is higher severity than the one to use the final keyword.
hemant Budhewar BamniBk wrote:Jeanne, it would be great if you explain me this static analysis rule which you are talking
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
|