• 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

 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do they say that hungarian notation violates OO abstraction ?
 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an interesting question. Could you cite where this was stated/who they are?
I would almost consider naming guidelines and OO principles as orthogonal to each other. However, I can see where people might take the position that variables names that indicate type, etc., would not be as abstract as a variable name that is purely domain based.
 
Sahir Shibley
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right here in the style sheet 3.3 (www.javaranch.com/style.html).
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the "Search" function at the upper right corner of the page to find past discussions using the phrase "hungarian notation" (or whatever other phrase you're interested in of course). Doing this, I find useful discussions here and here.
 
Trailboss
Posts: 23773
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote the style guide.
Hungarian notation violates abstraction because it reveals what is inside.
HN also makes code less maintainable. Suppose you want to change from and int to a long. If your variable is used 20 times, you have to change your code in 20 different places. Keep in mind that search and replace functions in editors are not always perfect.
 
Sahir Shibley
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But we do use hungarian notation in Delphi and C++ .
Besides if I wanted to cast one datatype to another I would
not use the same variable to do so.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think Paul was talking about casting. Imagine the situation where a customer changes a requirement so that you must now allow for more than 256 widget types in your system. Unofortunately you have used 'byte' for the number of widget types throughout your code.
Without HN, you only have to change the declarations of the variables from 'byte widgetCount' to 'int widgetCount' and recompile. If you use HN, you not only have to change 'byte bWidgetCount' to 'int iWidgetCount' in the declarations, but also everywhere it is used. And what if you have a method 'byte getWidgetCount()'?
In general, The use of HN makes every type change during maintenance a major headache, and (IMHO) gives very little in return..
 
Sahir Shibley
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Point taken. Thanks.
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic