You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@reef.apache.org by Andrew Chung <af...@gmail.com> on 2015/08/03 23:04:02 UTC

Convention on using "this"

Hi,

What is our guideline on using "this?" I've seen it used in some places of
the code but not in others. What's the recommended practice? Should there
be a checkstyle rule on it?

Thanks,
Andrew

Re: Convention on using "this"

Posted by Brian Cho <ch...@gmail.com>.
Given the alternative (all-or-nothing RequireThis), I’d rather just have a
guideline for ‘this’ for now.

Of course, developing a new checkstyle module with our desired behavior
would be nice. People outside of REEF should be interested as well (e.g.,
[1] has a lot of arguments against turning on RequireThis). I’m not sure
about the effort vs reward for REEF though.

Thanks,
Brian

[1]
http://stackoverflow.com/questions/1702111/should-the-requirethis-check-in-checkstyle-be-enabled

On Thu, Aug 6, 2015 at 3:24 AM, Mariia Mykhailova <ma...@microsoft.com>
wrote:

> RequireThis check is not fine-grained enough to distinguish between
> instance variables in constructors and setters and instance variables
> everywhere else. If we enable it, it has to be all instance variables (~4k
> violations to fix) or nothing. Or we have to find/write a custom check that
> is fine-grained enough.
>
> -Mariia
>
> -----Original Message-----
> From: Andrew Chung [mailto:afchung90@gmail.com]
> Sent: Tuesday, August 4, 2015 8:18 PM
> To: dev@reef.incubator.apache.org
> Subject: Re: Convention on using "this"
>
> OK sounds good, as long as we agree on a convention.
>
> On Tue, Aug 4, 2015 at 6:51 PM, John Yang <jo...@gmail.com> wrote:
>
> > +1 for Brian's proposal.
> >
> > Thanks,
> > John
> >
> > On Wed, Aug 5, 2015 at 9:40 AM, Byung-Gon Chun <bg...@gmail.com> wrote:
> >
> > > Ouch. I'd like to refine my vote. +1 for adding this for specific
> cases.
> > > I don't even think about adding this to instance method calls.
> > >
> > > On Wed, Aug 5, 2015 at 10:24 AM, Brian Cho <ch...@gmail.com> wrote:
> > >
> > > > It looks like we’re proving the point of “not using it
> > > > consistently” ;) Just to prove the point further…
> > > >
> > > > I agree with Jason that adding “this.” everywhere adds more noise
> > > > to
> > the
> > > > code. Does this guideline make sense?
> > > > 1. Only prepend “this.” for instance variables on constructors and
> > > setters.
> > > > 2. Never prepend “this.” for instance methods.
> > > >
> > > > Here’s some reasoning behind it:
> > > >
> > > > 1. For instance variables, I only prepend “this.” when there can
> > > > be confusion, i.e., local variables with the same name. With our
> > > > recent checkstyle changes, this should only be constructors and
> > > > setters. I
> > agree
> > > > with Jason that the highlighting is enough for other scenarios.
> > > >
> > > > 2. For instance methods, I don’t prepend “this.” at all. My IDE
> > > (Intellij)
> > > > makes it obvious when methods are static by italicizing, and
> > > > method
> > calls
> > > > of other instances must be prepended by that variable. So here, I
> > > disagree
> > > > with Andrew — to me instance method calls are obvious because of
> > > > their
> > > lack
> > > > of styling. Prepending “this.” might only confuse things.
> > > >
> > > > Thanks,
> > > > Brian
> > > >
> > > >
> > > > On Wed, Aug 5, 2015 at 5:46 AM, Andrew Chung <af...@gmail.com>
> > > wrote:
> > > >
> > > > > By default, it doesn't seem to provide different highlighting
> > > > > for
> > > > instance
> > > > > methods though.
> > > > >
> > > > > Thanks,
> > > > > Andrew
> > > > >
> > > > > On Tue, Aug 4, 2015 at 3:22 AM, Jason Jeong
> > > > > <cu...@gmail.com>
> > > > wrote:
> > > > >
> > > > > > I have a different opinion from others.
> > > > > >
> > > > > > IntelliJ does a great job in distinguishing class member
> > > > > > fields
> > from
> > > > > local
> > > > > > variables and parameters (at least for Java), by simply
> > > > > > coloring
> > > member
> > > > > > fields in a different color. I believe other IDEs pretty much
> > > > > > do
> > the
> > > > same
> > > > > > thing.
> > > > > >  Although the phrase "this." is only four letters and a
> > > > > > period, I
> > > > always
> > > > > > thought it was a bit tedious to type it when we could just
> > > > > > visually
> > > see
> > > > > the
> > > > > > coloring.
> > > > > >
> > > > > > Thanks,
> > > > > > Jason
> > > > > >
> > > > > >
> > > > > >
> > > > > > On Tue, Aug 4, 2015 at 7:10 AM, Mariia Mykhailova <
> > > > > mamykhai@microsoft.com>
> > > > > > wrote:
> > > > > >
> > > > > > > Corresponding checkstyle rule for Java is called
> > > > > > > RequireThis. It
> > > can
> > > > be
> > > > > > > configured separately to check fields and|or methods, but we
> > > probably
> > > > > > want
> > > > > > > both. In our code we have around 5700 violations (i.e.
> > > > > > > missing
> > > > `this`).
> > > > > > We
> > > > > > > can fix them and then add this check to our Java style.
> > > > > > >
> > > > > > > -Mariia
> > > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Byung-Gon Chun [mailto:bgchun@gmail.com]
> > > > > > > Sent: Monday, August 3, 2015 3:08 PM
> > > > > > > To: dev@reef.incubator.apache.org
> > > > > > > Subject: Re: Convention on using "this"
> > > > > > >
> > > > > > > +1 on using this
> > > > > > >
> > > > > > >
> > > > > > > On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <
> > afchung90@gmail.com>
> > > > > > wrote:
> > > > > > >
> > > > > > > > I've always had the habit of using it in front of class
> > > > > > > > members
> > > > just
> > > > > > > > to make it explicit.
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > > Andrew
> > > > > > > >
> > > > > > > > On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer
> > > > > > > > <markus@weimo.de
> > >
> > > > > wrote:
> > > > > > > >
> > > > > > > > > On 2015-08-03 14:04, Andrew Chung wrote:
> > > > > > > > > > What is our guideline on using "this?" I've seen it
> > > > > > > > > > used in
> > > > some
> > > > > > > > > > places
> > > > > > > > > of
> > > > > > > > > > the code but not in others. What's the recommended
> > practice?
> > > > > > > > > > Should
> > > > > > > > there
> > > > > > > > > > be a checkstyle rule on it?
> > > > > > > > >
> > > > > > > > > Good question. In C#, we follow the .NET OSS project's
> > > > > > > > > recommendation of avoiding `this`. In Java, we
> > > > > > > > > frequently use
> > > it,
> > > > > > > > > but not consistently, as you noted. I don't think we
> > converged
> > > > on a
> > > > > > > rule yet.
> > > > > > > > >
> > > > > > > > > Personally, I like using `this.` in front of class members.
> > How
> > > > do
> > > > > > > > > others feel?
> > > > > > > > >
> > > > > > > > > Markus
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Byung-Gon Chun
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Byung-Gon Chun
> > >
> >
>

RE: Convention on using "this"

Posted by Mariia Mykhailova <ma...@microsoft.com>.
RequireThis check is not fine-grained enough to distinguish between instance variables in constructors and setters and instance variables everywhere else. If we enable it, it has to be all instance variables (~4k violations to fix) or nothing. Or we have to find/write a custom check that is fine-grained enough.

-Mariia

-----Original Message-----
From: Andrew Chung [mailto:afchung90@gmail.com] 
Sent: Tuesday, August 4, 2015 8:18 PM
To: dev@reef.incubator.apache.org
Subject: Re: Convention on using "this"

OK sounds good, as long as we agree on a convention.

On Tue, Aug 4, 2015 at 6:51 PM, John Yang <jo...@gmail.com> wrote:

> +1 for Brian's proposal.
>
> Thanks,
> John
>
> On Wed, Aug 5, 2015 at 9:40 AM, Byung-Gon Chun <bg...@gmail.com> wrote:
>
> > Ouch. I'd like to refine my vote. +1 for adding this for specific cases.
> > I don't even think about adding this to instance method calls.
> >
> > On Wed, Aug 5, 2015 at 10:24 AM, Brian Cho <ch...@gmail.com> wrote:
> >
> > > It looks like we’re proving the point of “not using it 
> > > consistently” ;) Just to prove the point further…
> > >
> > > I agree with Jason that adding “this.” everywhere adds more noise 
> > > to
> the
> > > code. Does this guideline make sense?
> > > 1. Only prepend “this.” for instance variables on constructors and
> > setters.
> > > 2. Never prepend “this.” for instance methods.
> > >
> > > Here’s some reasoning behind it:
> > >
> > > 1. For instance variables, I only prepend “this.” when there can 
> > > be confusion, i.e., local variables with the same name. With our 
> > > recent checkstyle changes, this should only be constructors and 
> > > setters. I
> agree
> > > with Jason that the highlighting is enough for other scenarios.
> > >
> > > 2. For instance methods, I don’t prepend “this.” at all. My IDE
> > (Intellij)
> > > makes it obvious when methods are static by italicizing, and 
> > > method
> calls
> > > of other instances must be prepended by that variable. So here, I
> > disagree
> > > with Andrew — to me instance method calls are obvious because of 
> > > their
> > lack
> > > of styling. Prepending “this.” might only confuse things.
> > >
> > > Thanks,
> > > Brian
> > >
> > >
> > > On Wed, Aug 5, 2015 at 5:46 AM, Andrew Chung <af...@gmail.com>
> > wrote:
> > >
> > > > By default, it doesn't seem to provide different highlighting 
> > > > for
> > > instance
> > > > methods though.
> > > >
> > > > Thanks,
> > > > Andrew
> > > >
> > > > On Tue, Aug 4, 2015 at 3:22 AM, Jason Jeong 
> > > > <cu...@gmail.com>
> > > wrote:
> > > >
> > > > > I have a different opinion from others.
> > > > >
> > > > > IntelliJ does a great job in distinguishing class member 
> > > > > fields
> from
> > > > local
> > > > > variables and parameters (at least for Java), by simply 
> > > > > coloring
> > member
> > > > > fields in a different color. I believe other IDEs pretty much 
> > > > > do
> the
> > > same
> > > > > thing.
> > > > >  Although the phrase "this." is only four letters and a 
> > > > > period, I
> > > always
> > > > > thought it was a bit tedious to type it when we could just 
> > > > > visually
> > see
> > > > the
> > > > > coloring.
> > > > >
> > > > > Thanks,
> > > > > Jason
> > > > >
> > > > >
> > > > >
> > > > > On Tue, Aug 4, 2015 at 7:10 AM, Mariia Mykhailova <
> > > > mamykhai@microsoft.com>
> > > > > wrote:
> > > > >
> > > > > > Corresponding checkstyle rule for Java is called 
> > > > > > RequireThis. It
> > can
> > > be
> > > > > > configured separately to check fields and|or methods, but we
> > probably
> > > > > want
> > > > > > both. In our code we have around 5700 violations (i.e. 
> > > > > > missing
> > > `this`).
> > > > > We
> > > > > > can fix them and then add this check to our Java style.
> > > > > >
> > > > > > -Mariia
> > > > > >
> > > > > > -----Original Message-----
> > > > > > From: Byung-Gon Chun [mailto:bgchun@gmail.com]
> > > > > > Sent: Monday, August 3, 2015 3:08 PM
> > > > > > To: dev@reef.incubator.apache.org
> > > > > > Subject: Re: Convention on using "this"
> > > > > >
> > > > > > +1 on using this
> > > > > >
> > > > > >
> > > > > > On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <
> afchung90@gmail.com>
> > > > > wrote:
> > > > > >
> > > > > > > I've always had the habit of using it in front of class 
> > > > > > > members
> > > just
> > > > > > > to make it explicit.
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Andrew
> > > > > > >
> > > > > > > On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer 
> > > > > > > <markus@weimo.de
> >
> > > > wrote:
> > > > > > >
> > > > > > > > On 2015-08-03 14:04, Andrew Chung wrote:
> > > > > > > > > What is our guideline on using "this?" I've seen it 
> > > > > > > > > used in
> > > some
> > > > > > > > > places
> > > > > > > > of
> > > > > > > > > the code but not in others. What's the recommended
> practice?
> > > > > > > > > Should
> > > > > > > there
> > > > > > > > > be a checkstyle rule on it?
> > > > > > > >
> > > > > > > > Good question. In C#, we follow the .NET OSS project's 
> > > > > > > > recommendation of avoiding `this`. In Java, we 
> > > > > > > > frequently use
> > it,
> > > > > > > > but not consistently, as you noted. I don't think we
> converged
> > > on a
> > > > > > rule yet.
> > > > > > > >
> > > > > > > > Personally, I like using `this.` in front of class members.
> How
> > > do
> > > > > > > > others feel?
> > > > > > > >
> > > > > > > > Markus
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Byung-Gon Chun
> > > > > >
> > > > >
> > > >
> > >
> >
> >
> >
> > --
> > Byung-Gon Chun
> >
>

Re: Convention on using "this"

Posted by Andrew Chung <af...@gmail.com>.
OK sounds good, as long as we agree on a convention.

On Tue, Aug 4, 2015 at 6:51 PM, John Yang <jo...@gmail.com> wrote:

> +1 for Brian's proposal.
>
> Thanks,
> John
>
> On Wed, Aug 5, 2015 at 9:40 AM, Byung-Gon Chun <bg...@gmail.com> wrote:
>
> > Ouch. I'd like to refine my vote. +1 for adding this for specific cases.
> > I don't even think about adding this to instance method calls.
> >
> > On Wed, Aug 5, 2015 at 10:24 AM, Brian Cho <ch...@gmail.com> wrote:
> >
> > > It looks like we’re proving the point of “not using it consistently” ;)
> > > Just to prove the point further…
> > >
> > > I agree with Jason that adding “this.” everywhere adds more noise to
> the
> > > code. Does this guideline make sense?
> > > 1. Only prepend “this.” for instance variables on constructors and
> > setters.
> > > 2. Never prepend “this.” for instance methods.
> > >
> > > Here’s some reasoning behind it:
> > >
> > > 1. For instance variables, I only prepend “this.” when there can be
> > > confusion, i.e., local variables with the same name. With our recent
> > > checkstyle changes, this should only be constructors and setters. I
> agree
> > > with Jason that the highlighting is enough for other scenarios.
> > >
> > > 2. For instance methods, I don’t prepend “this.” at all. My IDE
> > (Intellij)
> > > makes it obvious when methods are static by italicizing, and method
> calls
> > > of other instances must be prepended by that variable. So here, I
> > disagree
> > > with Andrew — to me instance method calls are obvious because of their
> > lack
> > > of styling. Prepending “this.” might only confuse things.
> > >
> > > Thanks,
> > > Brian
> > >
> > >
> > > On Wed, Aug 5, 2015 at 5:46 AM, Andrew Chung <af...@gmail.com>
> > wrote:
> > >
> > > > By default, it doesn't seem to provide different highlighting for
> > > instance
> > > > methods though.
> > > >
> > > > Thanks,
> > > > Andrew
> > > >
> > > > On Tue, Aug 4, 2015 at 3:22 AM, Jason Jeong <cu...@gmail.com>
> > > wrote:
> > > >
> > > > > I have a different opinion from others.
> > > > >
> > > > > IntelliJ does a great job in distinguishing class member fields
> from
> > > > local
> > > > > variables and parameters (at least for Java), by simply coloring
> > member
> > > > > fields in a different color. I believe other IDEs pretty much do
> the
> > > same
> > > > > thing.
> > > > >  Although the phrase "this." is only four letters and a period, I
> > > always
> > > > > thought it was a bit tedious to type it when we could just visually
> > see
> > > > the
> > > > > coloring.
> > > > >
> > > > > Thanks,
> > > > > Jason
> > > > >
> > > > >
> > > > >
> > > > > On Tue, Aug 4, 2015 at 7:10 AM, Mariia Mykhailova <
> > > > mamykhai@microsoft.com>
> > > > > wrote:
> > > > >
> > > > > > Corresponding checkstyle rule for Java is called RequireThis. It
> > can
> > > be
> > > > > > configured separately to check fields and|or methods, but we
> > probably
> > > > > want
> > > > > > both. In our code we have around 5700 violations (i.e. missing
> > > `this`).
> > > > > We
> > > > > > can fix them and then add this check to our Java style.
> > > > > >
> > > > > > -Mariia
> > > > > >
> > > > > > -----Original Message-----
> > > > > > From: Byung-Gon Chun [mailto:bgchun@gmail.com]
> > > > > > Sent: Monday, August 3, 2015 3:08 PM
> > > > > > To: dev@reef.incubator.apache.org
> > > > > > Subject: Re: Convention on using "this"
> > > > > >
> > > > > > +1 on using this
> > > > > >
> > > > > >
> > > > > > On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <
> afchung90@gmail.com>
> > > > > wrote:
> > > > > >
> > > > > > > I've always had the habit of using it in front of class members
> > > just
> > > > > > > to make it explicit.
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Andrew
> > > > > > >
> > > > > > > On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer <markus@weimo.de
> >
> > > > wrote:
> > > > > > >
> > > > > > > > On 2015-08-03 14:04, Andrew Chung wrote:
> > > > > > > > > What is our guideline on using "this?" I've seen it used in
> > > some
> > > > > > > > > places
> > > > > > > > of
> > > > > > > > > the code but not in others. What's the recommended
> practice?
> > > > > > > > > Should
> > > > > > > there
> > > > > > > > > be a checkstyle rule on it?
> > > > > > > >
> > > > > > > > Good question. In C#, we follow the .NET OSS project's
> > > > > > > > recommendation of avoiding `this`. In Java, we frequently use
> > it,
> > > > > > > > but not consistently, as you noted. I don't think we
> converged
> > > on a
> > > > > > rule yet.
> > > > > > > >
> > > > > > > > Personally, I like using `this.` in front of class members.
> How
> > > do
> > > > > > > > others feel?
> > > > > > > >
> > > > > > > > Markus
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Byung-Gon Chun
> > > > > >
> > > > >
> > > >
> > >
> >
> >
> >
> > --
> > Byung-Gon Chun
> >
>

Re: Convention on using "this"

Posted by John Yang <jo...@gmail.com>.
+1 for Brian's proposal.

Thanks,
John

On Wed, Aug 5, 2015 at 9:40 AM, Byung-Gon Chun <bg...@gmail.com> wrote:

> Ouch. I'd like to refine my vote. +1 for adding this for specific cases.
> I don't even think about adding this to instance method calls.
>
> On Wed, Aug 5, 2015 at 10:24 AM, Brian Cho <ch...@gmail.com> wrote:
>
> > It looks like we’re proving the point of “not using it consistently” ;)
> > Just to prove the point further…
> >
> > I agree with Jason that adding “this.” everywhere adds more noise to the
> > code. Does this guideline make sense?
> > 1. Only prepend “this.” for instance variables on constructors and
> setters.
> > 2. Never prepend “this.” for instance methods.
> >
> > Here’s some reasoning behind it:
> >
> > 1. For instance variables, I only prepend “this.” when there can be
> > confusion, i.e., local variables with the same name. With our recent
> > checkstyle changes, this should only be constructors and setters. I agree
> > with Jason that the highlighting is enough for other scenarios.
> >
> > 2. For instance methods, I don’t prepend “this.” at all. My IDE
> (Intellij)
> > makes it obvious when methods are static by italicizing, and method calls
> > of other instances must be prepended by that variable. So here, I
> disagree
> > with Andrew — to me instance method calls are obvious because of their
> lack
> > of styling. Prepending “this.” might only confuse things.
> >
> > Thanks,
> > Brian
> >
> >
> > On Wed, Aug 5, 2015 at 5:46 AM, Andrew Chung <af...@gmail.com>
> wrote:
> >
> > > By default, it doesn't seem to provide different highlighting for
> > instance
> > > methods though.
> > >
> > > Thanks,
> > > Andrew
> > >
> > > On Tue, Aug 4, 2015 at 3:22 AM, Jason Jeong <cu...@gmail.com>
> > wrote:
> > >
> > > > I have a different opinion from others.
> > > >
> > > > IntelliJ does a great job in distinguishing class member fields from
> > > local
> > > > variables and parameters (at least for Java), by simply coloring
> member
> > > > fields in a different color. I believe other IDEs pretty much do the
> > same
> > > > thing.
> > > >  Although the phrase "this." is only four letters and a period, I
> > always
> > > > thought it was a bit tedious to type it when we could just visually
> see
> > > the
> > > > coloring.
> > > >
> > > > Thanks,
> > > > Jason
> > > >
> > > >
> > > >
> > > > On Tue, Aug 4, 2015 at 7:10 AM, Mariia Mykhailova <
> > > mamykhai@microsoft.com>
> > > > wrote:
> > > >
> > > > > Corresponding checkstyle rule for Java is called RequireThis. It
> can
> > be
> > > > > configured separately to check fields and|or methods, but we
> probably
> > > > want
> > > > > both. In our code we have around 5700 violations (i.e. missing
> > `this`).
> > > > We
> > > > > can fix them and then add this check to our Java style.
> > > > >
> > > > > -Mariia
> > > > >
> > > > > -----Original Message-----
> > > > > From: Byung-Gon Chun [mailto:bgchun@gmail.com]
> > > > > Sent: Monday, August 3, 2015 3:08 PM
> > > > > To: dev@reef.incubator.apache.org
> > > > > Subject: Re: Convention on using "this"
> > > > >
> > > > > +1 on using this
> > > > >
> > > > >
> > > > > On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <af...@gmail.com>
> > > > wrote:
> > > > >
> > > > > > I've always had the habit of using it in front of class members
> > just
> > > > > > to make it explicit.
> > > > > >
> > > > > > Thanks,
> > > > > > Andrew
> > > > > >
> > > > > > On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer <ma...@weimo.de>
> > > wrote:
> > > > > >
> > > > > > > On 2015-08-03 14:04, Andrew Chung wrote:
> > > > > > > > What is our guideline on using "this?" I've seen it used in
> > some
> > > > > > > > places
> > > > > > > of
> > > > > > > > the code but not in others. What's the recommended practice?
> > > > > > > > Should
> > > > > > there
> > > > > > > > be a checkstyle rule on it?
> > > > > > >
> > > > > > > Good question. In C#, we follow the .NET OSS project's
> > > > > > > recommendation of avoiding `this`. In Java, we frequently use
> it,
> > > > > > > but not consistently, as you noted. I don't think we converged
> > on a
> > > > > rule yet.
> > > > > > >
> > > > > > > Personally, I like using `this.` in front of class members. How
> > do
> > > > > > > others feel?
> > > > > > >
> > > > > > > Markus
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Byung-Gon Chun
> > > > >
> > > >
> > >
> >
>
>
>
> --
> Byung-Gon Chun
>

Re: Convention on using "this"

Posted by Byung-Gon Chun <bg...@gmail.com>.
Ouch. I'd like to refine my vote. +1 for adding this for specific cases.
I don't even think about adding this to instance method calls.

On Wed, Aug 5, 2015 at 10:24 AM, Brian Cho <ch...@gmail.com> wrote:

> It looks like we’re proving the point of “not using it consistently” ;)
> Just to prove the point further…
>
> I agree with Jason that adding “this.” everywhere adds more noise to the
> code. Does this guideline make sense?
> 1. Only prepend “this.” for instance variables on constructors and setters.
> 2. Never prepend “this.” for instance methods.
>
> Here’s some reasoning behind it:
>
> 1. For instance variables, I only prepend “this.” when there can be
> confusion, i.e., local variables with the same name. With our recent
> checkstyle changes, this should only be constructors and setters. I agree
> with Jason that the highlighting is enough for other scenarios.
>
> 2. For instance methods, I don’t prepend “this.” at all. My IDE (Intellij)
> makes it obvious when methods are static by italicizing, and method calls
> of other instances must be prepended by that variable. So here, I disagree
> with Andrew — to me instance method calls are obvious because of their lack
> of styling. Prepending “this.” might only confuse things.
>
> Thanks,
> Brian
>
>
> On Wed, Aug 5, 2015 at 5:46 AM, Andrew Chung <af...@gmail.com> wrote:
>
> > By default, it doesn't seem to provide different highlighting for
> instance
> > methods though.
> >
> > Thanks,
> > Andrew
> >
> > On Tue, Aug 4, 2015 at 3:22 AM, Jason Jeong <cu...@gmail.com>
> wrote:
> >
> > > I have a different opinion from others.
> > >
> > > IntelliJ does a great job in distinguishing class member fields from
> > local
> > > variables and parameters (at least for Java), by simply coloring member
> > > fields in a different color. I believe other IDEs pretty much do the
> same
> > > thing.
> > >  Although the phrase "this." is only four letters and a period, I
> always
> > > thought it was a bit tedious to type it when we could just visually see
> > the
> > > coloring.
> > >
> > > Thanks,
> > > Jason
> > >
> > >
> > >
> > > On Tue, Aug 4, 2015 at 7:10 AM, Mariia Mykhailova <
> > mamykhai@microsoft.com>
> > > wrote:
> > >
> > > > Corresponding checkstyle rule for Java is called RequireThis. It can
> be
> > > > configured separately to check fields and|or methods, but we probably
> > > want
> > > > both. In our code we have around 5700 violations (i.e. missing
> `this`).
> > > We
> > > > can fix them and then add this check to our Java style.
> > > >
> > > > -Mariia
> > > >
> > > > -----Original Message-----
> > > > From: Byung-Gon Chun [mailto:bgchun@gmail.com]
> > > > Sent: Monday, August 3, 2015 3:08 PM
> > > > To: dev@reef.incubator.apache.org
> > > > Subject: Re: Convention on using "this"
> > > >
> > > > +1 on using this
> > > >
> > > >
> > > > On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <af...@gmail.com>
> > > wrote:
> > > >
> > > > > I've always had the habit of using it in front of class members
> just
> > > > > to make it explicit.
> > > > >
> > > > > Thanks,
> > > > > Andrew
> > > > >
> > > > > On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer <ma...@weimo.de>
> > wrote:
> > > > >
> > > > > > On 2015-08-03 14:04, Andrew Chung wrote:
> > > > > > > What is our guideline on using "this?" I've seen it used in
> some
> > > > > > > places
> > > > > > of
> > > > > > > the code but not in others. What's the recommended practice?
> > > > > > > Should
> > > > > there
> > > > > > > be a checkstyle rule on it?
> > > > > >
> > > > > > Good question. In C#, we follow the .NET OSS project's
> > > > > > recommendation of avoiding `this`. In Java, we frequently use it,
> > > > > > but not consistently, as you noted. I don't think we converged
> on a
> > > > rule yet.
> > > > > >
> > > > > > Personally, I like using `this.` in front of class members. How
> do
> > > > > > others feel?
> > > > > >
> > > > > > Markus
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Byung-Gon Chun
> > > >
> > >
> >
>



-- 
Byung-Gon Chun

Re: Convention on using "this"

Posted by Brian Cho <ch...@gmail.com>.
It looks like we’re proving the point of “not using it consistently” ;)
Just to prove the point further…

I agree with Jason that adding “this.” everywhere adds more noise to the
code. Does this guideline make sense?
1. Only prepend “this.” for instance variables on constructors and setters.
2. Never prepend “this.” for instance methods.

Here’s some reasoning behind it:

1. For instance variables, I only prepend “this.” when there can be
confusion, i.e., local variables with the same name. With our recent
checkstyle changes, this should only be constructors and setters. I agree
with Jason that the highlighting is enough for other scenarios.

2. For instance methods, I don’t prepend “this.” at all. My IDE (Intellij)
makes it obvious when methods are static by italicizing, and method calls
of other instances must be prepended by that variable. So here, I disagree
with Andrew — to me instance method calls are obvious because of their lack
of styling. Prepending “this.” might only confuse things.

Thanks,
Brian


On Wed, Aug 5, 2015 at 5:46 AM, Andrew Chung <af...@gmail.com> wrote:

> By default, it doesn't seem to provide different highlighting for instance
> methods though.
>
> Thanks,
> Andrew
>
> On Tue, Aug 4, 2015 at 3:22 AM, Jason Jeong <cu...@gmail.com> wrote:
>
> > I have a different opinion from others.
> >
> > IntelliJ does a great job in distinguishing class member fields from
> local
> > variables and parameters (at least for Java), by simply coloring member
> > fields in a different color. I believe other IDEs pretty much do the same
> > thing.
> >  Although the phrase "this." is only four letters and a period, I always
> > thought it was a bit tedious to type it when we could just visually see
> the
> > coloring.
> >
> > Thanks,
> > Jason
> >
> >
> >
> > On Tue, Aug 4, 2015 at 7:10 AM, Mariia Mykhailova <
> mamykhai@microsoft.com>
> > wrote:
> >
> > > Corresponding checkstyle rule for Java is called RequireThis. It can be
> > > configured separately to check fields and|or methods, but we probably
> > want
> > > both. In our code we have around 5700 violations (i.e. missing `this`).
> > We
> > > can fix them and then add this check to our Java style.
> > >
> > > -Mariia
> > >
> > > -----Original Message-----
> > > From: Byung-Gon Chun [mailto:bgchun@gmail.com]
> > > Sent: Monday, August 3, 2015 3:08 PM
> > > To: dev@reef.incubator.apache.org
> > > Subject: Re: Convention on using "this"
> > >
> > > +1 on using this
> > >
> > >
> > > On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <af...@gmail.com>
> > wrote:
> > >
> > > > I've always had the habit of using it in front of class members just
> > > > to make it explicit.
> > > >
> > > > Thanks,
> > > > Andrew
> > > >
> > > > On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer <ma...@weimo.de>
> wrote:
> > > >
> > > > > On 2015-08-03 14:04, Andrew Chung wrote:
> > > > > > What is our guideline on using "this?" I've seen it used in some
> > > > > > places
> > > > > of
> > > > > > the code but not in others. What's the recommended practice?
> > > > > > Should
> > > > there
> > > > > > be a checkstyle rule on it?
> > > > >
> > > > > Good question. In C#, we follow the .NET OSS project's
> > > > > recommendation of avoiding `this`. In Java, we frequently use it,
> > > > > but not consistently, as you noted. I don't think we converged on a
> > > rule yet.
> > > > >
> > > > > Personally, I like using `this.` in front of class members. How do
> > > > > others feel?
> > > > >
> > > > > Markus
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Byung-Gon Chun
> > >
> >
>

Re: Convention on using "this"

Posted by Andrew Chung <af...@gmail.com>.
By default, it doesn't seem to provide different highlighting for instance
methods though.

Thanks,
Andrew

On Tue, Aug 4, 2015 at 3:22 AM, Jason Jeong <cu...@gmail.com> wrote:

> I have a different opinion from others.
>
> IntelliJ does a great job in distinguishing class member fields from local
> variables and parameters (at least for Java), by simply coloring member
> fields in a different color. I believe other IDEs pretty much do the same
> thing.
>  Although the phrase "this." is only four letters and a period, I always
> thought it was a bit tedious to type it when we could just visually see the
> coloring.
>
> Thanks,
> Jason
>
>
>
> On Tue, Aug 4, 2015 at 7:10 AM, Mariia Mykhailova <ma...@microsoft.com>
> wrote:
>
> > Corresponding checkstyle rule for Java is called RequireThis. It can be
> > configured separately to check fields and|or methods, but we probably
> want
> > both. In our code we have around 5700 violations (i.e. missing `this`).
> We
> > can fix them and then add this check to our Java style.
> >
> > -Mariia
> >
> > -----Original Message-----
> > From: Byung-Gon Chun [mailto:bgchun@gmail.com]
> > Sent: Monday, August 3, 2015 3:08 PM
> > To: dev@reef.incubator.apache.org
> > Subject: Re: Convention on using "this"
> >
> > +1 on using this
> >
> >
> > On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <af...@gmail.com>
> wrote:
> >
> > > I've always had the habit of using it in front of class members just
> > > to make it explicit.
> > >
> > > Thanks,
> > > Andrew
> > >
> > > On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer <ma...@weimo.de> wrote:
> > >
> > > > On 2015-08-03 14:04, Andrew Chung wrote:
> > > > > What is our guideline on using "this?" I've seen it used in some
> > > > > places
> > > > of
> > > > > the code but not in others. What's the recommended practice?
> > > > > Should
> > > there
> > > > > be a checkstyle rule on it?
> > > >
> > > > Good question. In C#, we follow the .NET OSS project's
> > > > recommendation of avoiding `this`. In Java, we frequently use it,
> > > > but not consistently, as you noted. I don't think we converged on a
> > rule yet.
> > > >
> > > > Personally, I like using `this.` in front of class members. How do
> > > > others feel?
> > > >
> > > > Markus
> > > >
> > >
> >
> >
> >
> > --
> > Byung-Gon Chun
> >
>

Re: Convention on using "this"

Posted by Jason Jeong <cu...@gmail.com>.
I have a different opinion from others.

IntelliJ does a great job in distinguishing class member fields from local
variables and parameters (at least for Java), by simply coloring member
fields in a different color. I believe other IDEs pretty much do the same
thing.
 Although the phrase "this." is only four letters and a period, I always
thought it was a bit tedious to type it when we could just visually see the
coloring.

Thanks,
Jason



On Tue, Aug 4, 2015 at 7:10 AM, Mariia Mykhailova <ma...@microsoft.com>
wrote:

> Corresponding checkstyle rule for Java is called RequireThis. It can be
> configured separately to check fields and|or methods, but we probably want
> both. In our code we have around 5700 violations (i.e. missing `this`). We
> can fix them and then add this check to our Java style.
>
> -Mariia
>
> -----Original Message-----
> From: Byung-Gon Chun [mailto:bgchun@gmail.com]
> Sent: Monday, August 3, 2015 3:08 PM
> To: dev@reef.incubator.apache.org
> Subject: Re: Convention on using "this"
>
> +1 on using this
>
>
> On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <af...@gmail.com> wrote:
>
> > I've always had the habit of using it in front of class members just
> > to make it explicit.
> >
> > Thanks,
> > Andrew
> >
> > On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer <ma...@weimo.de> wrote:
> >
> > > On 2015-08-03 14:04, Andrew Chung wrote:
> > > > What is our guideline on using "this?" I've seen it used in some
> > > > places
> > > of
> > > > the code but not in others. What's the recommended practice?
> > > > Should
> > there
> > > > be a checkstyle rule on it?
> > >
> > > Good question. In C#, we follow the .NET OSS project's
> > > recommendation of avoiding `this`. In Java, we frequently use it,
> > > but not consistently, as you noted. I don't think we converged on a
> rule yet.
> > >
> > > Personally, I like using `this.` in front of class members. How do
> > > others feel?
> > >
> > > Markus
> > >
> >
>
>
>
> --
> Byung-Gon Chun
>

RE: Convention on using "this"

Posted by Mariia Mykhailova <ma...@microsoft.com>.
Corresponding checkstyle rule for Java is called RequireThis. It can be configured separately to check fields and|or methods, but we probably want both. In our code we have around 5700 violations (i.e. missing `this`). We can fix them and then add this check to our Java style.

-Mariia

-----Original Message-----
From: Byung-Gon Chun [mailto:bgchun@gmail.com] 
Sent: Monday, August 3, 2015 3:08 PM
To: dev@reef.incubator.apache.org
Subject: Re: Convention on using "this"

+1 on using this


On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <af...@gmail.com> wrote:

> I've always had the habit of using it in front of class members just 
> to make it explicit.
>
> Thanks,
> Andrew
>
> On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer <ma...@weimo.de> wrote:
>
> > On 2015-08-03 14:04, Andrew Chung wrote:
> > > What is our guideline on using "this?" I've seen it used in some 
> > > places
> > of
> > > the code but not in others. What's the recommended practice? 
> > > Should
> there
> > > be a checkstyle rule on it?
> >
> > Good question. In C#, we follow the .NET OSS project's 
> > recommendation of avoiding `this`. In Java, we frequently use it, 
> > but not consistently, as you noted. I don't think we converged on a rule yet.
> >
> > Personally, I like using `this.` in front of class members. How do 
> > others feel?
> >
> > Markus
> >
>



--
Byung-Gon Chun

Re: Convention on using "this"

Posted by Byung-Gon Chun <bg...@gmail.com>.
+1 on using this


On Tue, Aug 4, 2015 at 6:47 AM, Andrew Chung <af...@gmail.com> wrote:

> I've always had the habit of using it in front of class members just to
> make it explicit.
>
> Thanks,
> Andrew
>
> On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer <ma...@weimo.de> wrote:
>
> > On 2015-08-03 14:04, Andrew Chung wrote:
> > > What is our guideline on using "this?" I've seen it used in some places
> > of
> > > the code but not in others. What's the recommended practice? Should
> there
> > > be a checkstyle rule on it?
> >
> > Good question. In C#, we follow the .NET OSS project's recommendation of
> > avoiding `this`. In Java, we frequently use it, but not consistently, as
> > you noted. I don't think we converged on a rule yet.
> >
> > Personally, I like using `this.` in front of class members. How do
> > others feel?
> >
> > Markus
> >
>



-- 
Byung-Gon Chun

Re: Convention on using "this"

Posted by Andrew Chung <af...@gmail.com>.
I've always had the habit of using it in front of class members just to
make it explicit.

Thanks,
Andrew

On Mon, Aug 3, 2015 at 2:41 PM, Markus Weimer <ma...@weimo.de> wrote:

> On 2015-08-03 14:04, Andrew Chung wrote:
> > What is our guideline on using "this?" I've seen it used in some places
> of
> > the code but not in others. What's the recommended practice? Should there
> > be a checkstyle rule on it?
>
> Good question. In C#, we follow the .NET OSS project's recommendation of
> avoiding `this`. In Java, we frequently use it, but not consistently, as
> you noted. I don't think we converged on a rule yet.
>
> Personally, I like using `this.` in front of class members. How do
> others feel?
>
> Markus
>

Re: Convention on using "this"

Posted by Markus Weimer <ma...@weimo.de>.
On 2015-08-03 14:04, Andrew Chung wrote:
> What is our guideline on using "this?" I've seen it used in some places of
> the code but not in others. What's the recommended practice? Should there
> be a checkstyle rule on it?

Good question. In C#, we follow the .NET OSS project's recommendation of
avoiding `this`. In Java, we frequently use it, but not consistently, as
you noted. I don't think we converged on a rule yet.

Personally, I like using `this.` in front of class members. How do
others feel?

Markus