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


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

Re: Using this

From Brixomatic <brixomatic@yahoo.com>
Newsgroups comp.lang.java.programmer
Subject Re: Using this
Date 2015-11-29 16:25 +0100
Organization Aioe.org NNTP Server
Message-ID <MPG.30c5372517331a259896a6@news.aioe.org> (permalink)
References <87poz5ytcf.fsf@Equus.decebal.nl>

Show all headers | View raw


In article <87poz5ytcf.fsf@Equus.decebal.nl>, Cecil Westerhof 
(Cecil@decebal.nl) says...
> 
> 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?

A matter of coding guidelines.
Coding guidelines should be agreed on in the group and kept rather 
stable to not introduce too many changes that are not changes in 
functionality.

Anyway.
The coding guidelines that I've seen the most, and that I find the most 
practical too, are to use "this" only when necessary.

Some guidelines discourage shadowing a field name with parameter names, 
so the field would be called "x" and the method parameter would be 
called "_x" or "theX" or something. But I got to hate that.
Yes, it may protect you from using a field/paremeter when you really 
want to use the other, but seriously: 1992 is gone, todays's code 
editing tools have syntax highlighting that show the difference. Plus it 
is annoying when you change a method from say static to instance bound 
or back and use the field values (or the other way round) and have to 
rename all the usages (yes, IDEs make that easier too, but it sucks 
anyway). I have wasted more time changing the names for not good reason 
other than to adhere to that code guiseline, than solving problems with 
shadowing.
And that's almost the same annoyance that you see get with excessively 
using "this".

But as I said: You should dicuss that as a team and then stick to it. 
Also: Sharing the auto-formatter settings of your IDE in the source code 
repository is helpful to enforce it.


Kind regards,
Wanja

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