Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news.netfront.net!not-for-mail From: Wanja Gayk Newsgroups: comp.lang.java.programmer Subject: Re: Inserting In a List Date: Sat, 6 Apr 2013 21:39:02 +0200 Organization: Netfront http://www.netfront.net/ Lines: 62 Message-ID: References: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> NNTP-Posting-Host: 77.8.248.100 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: adenine.netfront.net 1365276994 83221 77.8.248.100 (6 Apr 2013 19:36:34 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Sat, 6 Apr 2013 19:36:34 +0000 (UTC) User-Agent: MicroPlanet-Gravity/3.0.4 Xref: csiph.com comp.lang.java.programmer:23353 In article , lipska the kat (lipska the kat) says... > Just as a matter of interest what's with all the finals > > particularly > > for (final File name : folder.listFiles()) > > Despite initial appearances this is indeed legal as the > assignment is made multiple times but from the same statement. > > Given that the final keyword is, aside from a flag to the compiler for > possible optimization, largely documentary, what is the point of making > name final. > > In fact what does peppering the code with finals do to make it easily > understandable to an inexperienced developer ? In my opinion it's been an unfortunate decision to have a "final" keyword instead of a "var" keyword with a "final" default. Now, I'm a fan of using the "final" keyword everywhere possible apart from method and class declarations and I'll give you my reasons behind it. a) It expresses more exactly what the code really does. I think that a certain precision of expression is of beauty. This is a rather stylistic view. b) As soon as you're used to having every possible assignment declared "final", each missing "final" will stand out like an alarm sign - you immedeately spot those assignments that change their value. It greatly helps me understand the code. So it is of practical value, once you're used to it. c) If I mistakingly (mistyping, code completion errs) assign a value to a "final" reference, the compiler will warn me immediately. Since I always declare "final" what is never intended to change, this stops me from making stupid mistakes. I find this is of a hugepractical value. d) I hardly have any problem with using a value in an anonymous class and if I have, It tells me that I'm probably doing something stupid. e) Adding parameters to methods is a code smell, each "final" keyword augments that by growing the signature even faster. I find it funny, that one of the biggest design mistakes in the language (no final default) is actually of some benefit here. Once you always use "final" where appropriate, and became used to it, the visual clutter starts to disappear. Kind regards, -Wanja- -- ..Alesi's problem was that the back of the car was jumping up and down dangerously - and I can assure you from having been teammate to Jean Alesi and knowing what kind of cars that he can pull up with, when Jean Alesi says that a car is dangerous - it is. [Jonathan Palmer] --- news://freenews.netfront.net/ - complaints: news@netfront.net ---