aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Variable Naming Conventions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Variable Naming Conventions" Watch "Variable Naming Conventions" New topic
Author

Variable Naming Conventions

Denis Zjukow
Ranch Hand

Joined: Mar 15, 2006
Posts: 39
Hi. I got a question to authors of "SCJD Exam with J2SE 5". There is a note at the bottom of page 21 which says: "The Sun Coding Conventions specify that you should apply the same naming convention to all instance, class, and local variables. Be aware that you may see code written by other coders where instance or class variables are signified by an underscore or some other special mark. Another way to achieve the same effect is by using the convention variable when referring to a local variable, this.variable when reffering to an instance variable, and Class.variable when referring to a class variable. Doing so makes it explicit which type of variable you are referring to."
Could you please provide a sample code clarifying the part in bold. And one other question about variable naming conventions: can I use some kind of prefixes for naming variables say 'a', 'an' for arguments 'the' for local variables and something like 'i' for fields? Thank you.
Jar Jaquiso
Greenhorn

Joined: Apr 20, 2006
Posts: 26
There you are:


[ May 12, 2006: Message edited by: Jar Jaquiso ]
[ May 12, 2006: Message edited by: Jar Jaquiso ]
Denis Zjukow
Ranch Hand

Joined: Mar 15, 2006
Posts: 39
Originally posted by Jar Jaquiso:
There you are:


[ May 12, 2006: Message edited by: Jar Jaquiso ]

[ May 12, 2006: Message edited by: Jar Jaquiso ]


Ok, thanks. I was just confused by 'Class.variable'. It looks like 'variable' is a static field of Class class .
But what's about the second question?
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Using prefixes, postfixes, and such is extremely poor coding style.
Definitely NOT do that, if I were an assessor (I'm not) I'd detract serious points for just that.
I've written styleguides in the past, and they've always said to not do it.
So does the Sun styleguide which is what you have to follow.
So do most others, except the ones promoted by Microsoft for Visual Studio (which still use Hungarian notation which your idea is a weaker version of).

I now have to use it at work, but not for much longer (as I'm switching jobs) and it's a disaster. Completely unnecessary, complicates typing and makes changing the type of something next to impossible as it would mean massive code changes just to get the variable names to match their types again.


42
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

Originally posted by Jeroen T Wenting:
Using prefixes, postfixes, and such is extremely poor coding style.
I agree, and I am sorry that the note makes it appear that we are recommending this. We certainly do not recommend it, and you will see that we do not use prefixes in the book or in our sample code.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
I was referring to the last sentence by the OP, not the quote from your book (though maybe the OP misunderstood that note to mean using prefixes).
Denis Zjukow
Ranch Hand

Joined: Mar 15, 2006
Posts: 39
Thank you all. I actually didn't know that using prefixes/postfixes was such a bad thing. Saying the truth we used prefixes at work and I found it usefull . But now I know this is a bad practice and I will certainly NOT use it in my SCJD project!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variable Naming Conventions