Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!texta.sil.at!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mail Newsgroups: comp.lang.java.programmer From: Andreas Leitgeb Subject: Re: Style Police (a rant) References: Reply-To: avl@logic.at User-Agent: slrn/pre0.9.9-111 (Linux) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: Date: 11 Sep 2011 14:07:31 GMT Lines: 56 NNTP-Posting-Host: gamma.logic.tuwien.ac.at X-Trace: 1315750051 tunews.univie.ac.at 71616 128.130.175.3 X-Complaints-To: abuse@tuwien.ac.at Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7797 Lew wrote: > Andreas Leitgeb wrote: >> I'd favor a different change: let final variables optionally >> have their type inferred: >> final myList = new ArrayList(); >> Afterall, it is just a handle for some previously obtained value. > That idea is more complex than it appears. Should the inferred type be > 'List', 'AbstractList' or 'ArrayList'? > I suspect you would say the last, You suspected right, which is no surprise, as it is the only reasonable choice in that particular context. > but really, is it so very, very bad to type > final List myList = new ArrayList<>(); I find the direction of the inferral somewhat unlucky. I'd rather infer the type from right(expression) to left(variable), than the other way round. I guess that was discussed thoroughly before it was introduced, so I might just miss knowing those perfect arguments against my preferrence. > ? I mean, if you want to talk hard work, an extra second or so of > typing really doesn't qualify, It seems that you're biased towards reading other's code versus writing your own. Typing long code isn't the problem - typing redundant boilerplates is ... fatigueing. It dumbs the joy of programming. > especially since the lack of the supposedly "redundant" types would > harm readability for maintainers. That is a claim, of whose truth I'm not at all convinced. If in a particular situation, the type really wasn't obvious, then there'd still be the choice of making it explicit. > As one whose career has involved far more maintenance of existing > code than development of new, I much prefer the explicit typing. So much to affirm the diagnosed bias... > Wanja's main point is that 'final' has a semantic purpose, not an > optimization one. So far I agree. > I agree that the evidence for the advantage of a 'var' keyword > over a 'final' is lacking, That Wanja suggested the "var" keyword is an indication of that he has a bias towards functional programming. Unlike Arne, I don't say that "pick a different language" is an appropriate answer. It's ok, to program functionally in Java, as far as possible in Java-syntax, and that this may lead to quite a lot of "final"s. I just disagree with Wanja as to making "final" the default: it's like bullying others to functional style in Java.