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


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

Re: Using this

Newsgroups comp.lang.java.programmer
Date 2015-11-20 05:43 -0800
References <87poz5ytcf.fsf@Equus.decebal.nl>
Message-ID <32d97b3b-41ca-40b9-88b1-08e092be89d7@googlegroups.com> (permalink)
Subject Re: Using this
From Eric Douglas <e.d.programmer@gmail.com>

Show all headers | View raw


On Friday, November 20, 2015 at 3:44:11 AM UTC-5, 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?

I only use it where necessary, but it's often just a personal preference, so if you're working on someone else's API you probably want to stay consistent to any convention they've used.  I don't know many scenarios where I've personally used it offhand, mostly in overloading constructors.  If for instance you use Eclipse to auto-write a getter-setter method they use the class variable as the method variable name and put in this.var=var by default but I think that's ugly if not confusing.  I think class variables and method variables should have different names.

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