Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33153

Re: Using this

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Using this
Date Fri, 20 Nov 2015 08:15:15 -0500
Organization A noiseless patient Spider
Lines 30
Message-ID <n2n68r$6j2$1@dont-email.me> (permalink)
References <87poz5ytcf.fsf@Equus.decebal.nl>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Fri, 20 Nov 2015 13:12:59 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="858a9d65d95f4ea4d355bd116aa2cdbf"; logging-data="6754"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/O/IcaJMJ7kZ70n3yzOddf"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0
In-Reply-To <87poz5ytcf.fsf@Equus.decebal.nl>
Cancel-Lock sha1:Z/FjyKSf/plsmqRqJsMOok1QGsY=
Xref csiph.com comp.lang.java.programmer:33153

Show key headers only | View raw


On 11/20/2015 3:21 AM, Cecil Westerhof wrote:
> What is the ‘best’ way to use this? I normally only use it when
> necessary. (A function has a parameter with the same name.) But at the
> company I am working there are people who say you should use it
> always. This resulted at on line of code with four times a this. Made
> the line a lot longer and I find it very ugly. Is there a rational for
> constantly using this?

     Maybe you should ask the people who tell you to use it.

     Speaking for myself (and not for those people whose opinions
I don't know), I use `this' explicitly:

     - In constructors, to invoke a different constructor version,

     - In constructors, to set an instance field from a parameter
       of the same name,

     - In equals() methods, where I like to compare instance fields
       of `this' object and `that' object,

     - When the phase of the moon is favorable.

Perhaps your associates feel that an explicit `this' is a good way
to distinguish element uses from variable or parameter uses?  I
don't know; ask them.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Using this Cecil Westerhof <Cecil@decebal.nl> - 2015-11-20 09:21 +0100
  Re: Using this Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-20 08:15 -0500
  Re: Using this Eric Douglas <e.d.programmer@gmail.com> - 2015-11-20 05:43 -0800
  Re: Using this Martin Gregorie <martin@address-in-sig.invalid> - 2015-11-20 21:52 +0000
    Re: Using this Martin Gregorie <martin@address-in-sig.invalid> - 2015-11-20 22:41 +0000
  Re: Using this Arne Vajhøj <arne@vajhoej.dk> - 2015-11-20 20:26 -0500
  Re: Using this Brixomatic <brixomatic@yahoo.com> - 2015-11-29 16:25 +0100
  Re: Using this Lew <lewbloch@gmail.com> - 2015-11-29 22:51 -0800

csiph-web