• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hungarian Notation is a no no

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quote:
Hungarian notation is a no, no. Pick another identifier for strNumber
------------------------
Maybe I'm just tired, but what does "Hungarian notation" mean?
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hungarian notation is when part of your variable is named by the data type.
For example:
strNumber for a number string
iNumber for an integer
arrNumber for an array of numbers
blnNumber for a boolean
This is a habit I am still trying to break.
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same here Daniel. Hungarian notation became popular with VB programmers. It is there because you can glance at a variable and no that it is an integer or a string based on the first two or three letters.
But this isn't really good OO programming which Java is, unlike VB. You create any class that you want, so what would you prepend to those? In VB, I used to use objXXX to show it is an object, but in Java everything is an object, so that would look kind of silly.
So, now I just use good and self documenting identifiers like:
name
numberOfArgs
firstName
Bill
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a big fan of the cornerstone of OO: abstraction. There are plenty of times where we shouldn't care what type the object is.
For instance, what if you write a program using an integer variable named iNumber. Later you decide to use a long. Now you have to go all through your program changing all the iNumber variables to lNumber variables. What if you miss one?

Or perhaps you are using an array named arrNames to store some stuff. Now you want to change the storage container from an array to a HashMap. A year from now some poor soul is going to be wondering why you named your HashMap arrNames.

It's better to have the variable describe what the variable represents than what data type it is.
 
Josue Cedeno
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Everyone!
I actually started with VB programming, which is where this bad habit started. I'll try to keep your suggestions in mind.
------------------
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic