cba
Am 28. August 2015 02:36:27 GMT-04:00, schrieb Thomas Mueller <[email protected]>: >Hi, > >I wonder what does the team think about using "final" for variables and >parameters. In Oak, so far we didn't use it a lot. This question has >come up with OAK-3148. The patch uses "final" for variables, but not >for parameters. Lately, I have seens some code (I forgot where) that >uses "final" for parameters in an _interface_. Please note this is not >about using "final" for fields, where I think everybody agrees it >should be used. It's just about variables and parameters. > >I think we have 3 options: > >(a) use "final" for variables and parameters everywhere possible > >(b) let the individual developer decide > >(c) don't use it except if needed > >Some links: >http://stackoverflow.com/questions/154314/when-should-one-use-final-for-method-parameters-and-local-variables >http://stackoverflow.com/questions/137868/using-final-modifier-whenever-applicable-in-java > >Personally, my favorite is (c), followed by (b). As for (a), I think >(same as Alex Miller at StackOverflow) it clutters the code and >decreases readability. Too bad "final" is not the default in Java, but >Java will not change, and we are stuck with Java. I think using "final" >will not improve the code, because people don't "accidentally" change >variables and parameters, so it will not help the writer of a method, >it will not help the compiler or performance (the JVM can easily see if >a variable or parameter is effectively assigned only once). To improve >the code, I'm all for using Checkstyle, unit tests, code coverage, >mutation testing, enforcing to write Javadocs for interfaces, and so >on. But using "final" wherever possible, I think it would be a step >backwards. > >Regards, >Thomas
