File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Is this bad form? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is this bad form?" Watch "Is this bad form?" New topic

Is this bad form?

Brandt Charles
Ranch Hand

Joined: Apr 17, 2006
Posts: 57

I'm completing an assignment for class which will involve a JFrame with multiple buttons, textfields, etc. Is it acceptable naming convention to name the objects btnHelp (for the help button), txtInput(for the textfield where text is displayed)? I believe this is referred to as the Hungarian notation. Even if it's not, I remember this being the convention for VB 5, and I thought it was easy to identify what sort of component you were dealing with in the code. However, I recall my instructor grumbling about "not being Hungarian" or something, so if it's considered bad coding I would like to know. So, is this one of the accepted naming conventions or not?



Green, green, green!
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

i'm sure people will argue this one for days. however, according to the JavaRanch style guide, it should not be used.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Guides or no guides, you almost never see it used in Java code in the wild. Pick any open-source project at random and download its source code, I will bet long odds that it does not use Hungarian notation. If "acceptable" means "what everybody does", that should take care of "acceptable".
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
If you work for Microsoft, it's an accepted convention. If you work for almost anyone else, it's frowned upon.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

But you'll very often see

JButton helpButton = ...

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Is this bad form?
jQuery in Action, 3rd edition