Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Checkstyle "hides a field" strategy.
Checkstyle "hides a field" strategy. [message #468321] Tue, 04 August 2009 22:51 Go to next message
ali Mising name is currently offline ali Mising name
Messages: 38
Registered: July 2009
Member
Hello all,

'Just wondering if anyone knows of any standard or common practices to
resolve this code style issue of "hides a field". I want to use meaningful
variable names for both of my local and class variables, but I’m not sure
which one to modify of what to modify it too...

Does anyone insert trailing or leading characters to denote class
variables, or perhaps append the word "param" to the end of the parameter
names? I appreciate why and how this issue occurs – I am seeking advice
about a standard naming approach to solving it (best practice).

Here's an example - checkstyle may complain that the "value" parameter
"hides a field":

public class MyClass {
private int value;
public void setValue(int value) {
this.value = value;
}
}
Re: Checkstyle "hides a field" strategy. [message #468326 is a reply to message #468321] Wed, 05 August 2009 01:33 Go to previous messageGo to next message
Lars Vogel is currently offline Lars Vogel
Messages: 1048
Registered: July 2009
Senior Member

Hi,

If I remember correctly I have turned this check of. Best regards, Lars

ali wrote:
> Hello all,
>
> 'Just wondering if anyone knows of any standard or common practices to
> resolve this code style issue of "hides a field". I want to use
> meaningful variable names for both of my local and class variables, but
> I�m not sure which one to modify of what to modify it too...
>
> Does anyone insert trailing or leading characters to denote class
> variables, or perhaps append the word "param" to the end of the
> parameter names? I appreciate why and how this issue occurs � I am
> seeking advice about a standard naming approach to solving it (best
> practice).
>
> Here's an example - checkstyle may complain that the "value" parameter
> "hides a field":
>
> public class MyClass {
> private int value;
> public void setValue(int value) {
> this.value = value;
> }
> }
>




--
http://www.vogella.de/ - Eclipse plugin and Eclipse RCP Tutorials
Re: Checkstyle "hides a field" strategy. [message #468329 is a reply to message #468326] Wed, 05 August 2009 01:59 Go to previous messageGo to next message
ali Mising name is currently offline ali Mising name
Messages: 38
Registered: July 2009
Member
Yeah, that would be a bit easier, but I do like the "tough-love" of
abiding by this rule... I think in the long-run it will make code easier
to read (if I can settle on a good, standard way of implementing it). Any
advice from anyone else would be very welcome.
Re: Checkstyle "hides a field" strategy. [message #468336 is a reply to message #468321] Wed, 05 August 2009 03:24 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
ali wrote:
> Hello all,
>
> 'Just wondering if anyone knows of any standard or common practices to
> resolve this code style issue of "hides a field". I want to use
> meaningful variable names for both of my local and class variables,
> but I�m not sure which one to modify of what to modify it too...
>
> Does anyone insert trailing or leading characters to denote class
> variables, or perhaps append the word "param" to the end of the
> parameter names? I appreciate why and how this issue occurs � I am
> seeking advice about a standard naming approach to solving it (best
> practice).
Some Eclipse SDK components (e.g. JDT) use 'f' as prefix for instance
fields and 'fg' for static fields. Prefixes and suffixes are supported
by JDT (take a look at Java > Code Style preference page).

Dani
>
> Here's an example - checkstyle may complain that the "value" parameter
> "hides a field":
>
> public class MyClass {
> private int value;
> public void setValue(int value) {
> this.value = value;
> }
> }
>
Re: Checkstyle "hides a field" strategy. [message #468437 is a reply to message #468321] Wed, 05 August 2009 10:27 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric Rizzo
Messages: 2227
Registered: July 2009
Senior Member
ali wrote:
> Hello all,
>
> 'Just wondering if anyone knows of any standard or common practices to
> resolve this code style issue of "hides a field". I want to use
> meaningful variable names for both of my local and class variables, but
> I�m not sure which one to modify of what to modify it too...
>
> Does anyone insert trailing or leading characters to denote class
> variables, or perhaps append the word "param" to the end of the
> parameter names? I appreciate why and how this issue occurs � I am
> seeking advice about a standard naming approach to solving it (best
> practice).
>
> Here's an example - checkstyle may complain that the "value" parameter
> "hides a field":
>
> public class MyClass {
> private int value;
> public void setValue(int value) {
> this.value = value;
> }
> }
>

In this particular case, I'd use a name for the method parameter like
newValue. In other situations, I often use names like aValue or aString
(comes from my Smalltalk background, where that is a "standard" naming
convention).

By the way, Eclipse does not use Chekstyle (the SourceForge project);
these things are called "compiler warnings" in Eclipse lingo.

Hope this helps,
Eric
Re: Checkstyle "hides a field" strategy. [message #474801 is a reply to message #468437] Wed, 05 August 2009 17:52 Go to previous message
ali Mising name is currently offline ali Mising name
Messages: 38
Registered: July 2009
Member
Hi Eric,

Thanks for the suggestions - I'm leaning heavily towards adding the word
"new" to my method parameters. I've seen that used before too - so it
"feels" like some sort of common approach. BTW, I am using a Checkstyle
plug-in for Eclipse and I am attempting to fully-accommodate the Sun
checkstyle rules.
Previous Topic:Icons from other projects
Next Topic:Is it possible to replace the "Default Text Editor"
Goto Forum:
  


Current Time: Wed Aug 20 04:50:09 EDT 2014

Powered by FUDForum. Page generated in 0.17485 seconds