File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Naming conventions advice

 
scottie zman
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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?
thanks
Zman
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never seen this actually implemented, but it does sound like a good idea.
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic