Return-Path: Delivered-To: apmail-lucene-mahout-dev-archive@minotaur.apache.org Received: (qmail 85384 invoked from network); 7 Nov 2009 13:10:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Nov 2009 13:10:59 -0000 Received: (qmail 77861 invoked by uid 500); 7 Nov 2009 13:10:58 -0000 Delivered-To: apmail-lucene-mahout-dev-archive@lucene.apache.org Received: (qmail 77785 invoked by uid 500); 7 Nov 2009 13:10:57 -0000 Mailing-List: contact mahout-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: mahout-dev@lucene.apache.org Delivered-To: mailing list mahout-dev@lucene.apache.org Received: (qmail 77775 invoked by uid 99); 7 Nov 2009 13:10:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Nov 2009 13:10:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Nov 2009 13:10:53 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 67515234C045 for ; Sat, 7 Nov 2009 05:10:32 -0800 (PST) Message-ID: <1550032018.1257599432408.JavaMail.jira@brutus> Date: Sat, 7 Nov 2009 13:10:32 +0000 (UTC) From: "Sean Owen (JIRA)" To: mahout-dev@lucene.apache.org Subject: [jira] Updated: (MAHOUT-190) Make all instance fields private In-Reply-To: <327928161.1256646419351.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/MAHOUT-190?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Sean Owen updated MAHOUT-190: ----------------------------- Attachment: MAHOUT-190_2.patch OK went ahead and made the rest of the changes I think are appropriate given discussion on the issue. Final part 2 patch attached, looking to submit Monday. > Make all instance fields private > -------------------------------- > > Key: MAHOUT-190 > URL: https://issues.apache.org/jira/browse/MAHOUT-190 > Project: Mahout > Issue Type: Improvement > Affects Versions: 0.2 > Reporter: Sean Owen > Assignee: Sean Owen > Priority: Minor > Fix For: 0.3 > > Attachments: MAHOUT-190_1.patch, MAHOUT-190_2.patch, MAHOUT-190_2.patch > > > This one may be more controversial but is useful and interesting enough to discuss. > I personally believe instance fields should always be private. I think the pro- and con- debate goes like this: > Making all fields private increases encapsulation. Fields must be made explicitly accessible via getters and setters, which is good -- default to hiding, rather than exposing. Not-hiding a field amounts to committing it to be a part of the API, which is rarely intended. Using getters/setters allows read/write access to be independently controlled and even allowed -- allows for read-only 'fields'. Getters/setters establish an API independent from the representation which is a Good Thing. > But don't getters and setters slow things down? > Trivially. JIT compilers will easily inline one-liners. Making fields private more readily allows fields to be marked final, and these two factors allow for optimizations by (Proguard or) JIT. It could actually speed things up. > But isn't it messy to write all those dang getters/setters? > Not really, and not at all if you use an IDE, which I think we all should be. > But sometimes a class needs to share representation with its subclasses. > Yes, and it remains possible with package-private / protected getters and setters. This is IMHO a rare situation anyway, and, the code is far easier to read when fields from a parent don't magically appear, or one doesn't wonder about where else a field may be accessed in subclasses. I also feel like sometimes making a field more visible is a shortcut enabler to some bad design. It usually is a bad smell. > Thoughts on this narrative. Once again I volunteer to implement the consensus. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.