jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Naming conventions advice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Naming conventions advice" Watch "Naming conventions advice" New topic

Naming conventions advice

scottie zman
Ranch Hand

Joined: Aug 08, 2001
Posts: 40
I've created a class for a bug tracking app, it's called Bug. Bug has some properties like ID, author, dateadded, etc. It also has a validate method, which checks for values being present before it can enter the bug in a DB.
That's all fine...
then I created another class, an extension of Bug, called Comment. Comment is for programmers to comment on the progress of the bug. It has properties like ID, author, dateAdded, etc, as well as a validate method. A Bug can have a vector of comments.
I had some trouble tracking down a scope-related error because I had accidentally crossed up some variable names between the two classes.
I was wondering if anyone has some general Java advice for correctly dealing with/naming variables in an extended class. Should I simply preface all the variables and methods within Comment with "cmt" or something like that, or is there a more elegant way. My instinct says to do that, because I will then be able to use those same names in HTML forms. But I was just wondering if there is a better way of doing it?
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
I have never seen this actually implemented, but it does sound like a good idea.

"JavaRanch, where the deer and the Certified play" - David O'Meara
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Some people use a prefix for the different type of variables. So a class variable could have a prefix of "m_", a parameter variable could have a prefix of "p_" and local variables not have any.
Having a prefix (or some other type of identifier) for variables in a subclass wouldn't be a good idea. I don't think that you would want to jump though hoops to name your variables for the small number of times you have errors with scope. You should write your code with the assumption that it isn't going to break.
(Maybe a more detailed example of the problem you are having would be helpful.)

Please ignore post, I have no idea what I am talking about.
I agree. Here's the link: http://aspose.com/file-tools
subject: Naming conventions advice
It's not a secret anymore!