Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this bad form?

 
Brandt Charles
Ranch Hand
Posts: 57
Chrome IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks,

Brandt
 
fred rosenberger
lowercase baba
Bartender
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm sure people will argue this one for days. however, according to the JavaRanch style guide, it should not be used.
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you work for Microsoft, it's an accepted convention. If you work for almost anyone else, it's frowned upon.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you'll very often see

JButton helpButton = ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic