Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #861

Re: Hungarian Notation and Java

From lewbloch <lewbloch@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Hungarian Notation and Java
Date 2011-07-13 08:47 -0700
Organization http://groups.google.com
Message-ID <1e5efca0-bba1-4a71-9ea6-15399b85e767@k23g2000pri.googlegroups.com> (permalink)
References <b4d806bc-4f94-4655-8699-5e1c32e111ed@q1g2000vbj.googlegroups.com>

Show all headers | View raw


Steve wrote:
> Is there any reason left to use Hungarian notation with Java?
>

"left"?  There never was any reason (other than emotional) to use
Hungarian notation with any language, much less Java.  The Java naming
conventions, published in 1999, make no mention of it.
<http://www.oracle.com/technetwork/java/codeconv-138413.html>

So where do you get "left"?

> Many free IDEs have code completion, so anyone can click on a variable
> and get a list of available functions, so there is less of a need to
> know the datatype.    Also, with polymorphism many Java objects will
> not have a "single" datatype, so a hungarian [sic] notation will not be
> completely accurate.
>

Not correct.  An object has a single type - its own type - always.
Alternatively, you can say that every object not itself of type
'Object' has many types, i.e., all those of which its leaf type is a
subtype.

Regardless, Hungarian notation never was "completely accurate" at
indicating type.  Furthermore, it's only a commenting standard.  Have
you never seen code where the comments and the code itself diverged
over time?  Java has a compiler-enforced type system.

> Am I missing some advantage of Hungarian notation that would still
> make it worthwhile using with Java?
>

Why do you even bother asking this question?

> Is there an emerging naming convention in Java to do what Hungarian
> notation did......put something in the variable name, in a standard
> way, that gives you a clue as to what the variable is?

There is the standard Java coding conventions, modified by house
standards for any given project.

These standards have been in play for quite a while, nearly as long as
Java has been popular.

The point of the naming conventions is to indicate not what a variable
"is", whatever the heck you mean by that, but what its domain purpose
is.  For example, a variable to hold the total number of widgets at
some point in an algorithm might be called 'totalNumberOfWidgets', or
more tersely, 'widgetTotal'.  Whether the type is 'double' or 'Double'
or 'BigInteger' is not needed in the name, because the freaking
declaration (say, 'BigInteger widgetTotal;') completely expresses
that.

Forget about Hungarian notation and use the well-documented and
universally-known coding standards about which no one can be ignorant
and still lay claim to being a Java programmer.

(There are some minor variations in practice that many people accept.
That's an Editor Wars debate for another thread.)

--
Lew

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Hungarian Notation and Java Steve <tinker123@gmail.com> - 2011-07-13 07:46 -0700
  Re: Hungarian Notation and Java lewbloch <lewbloch@gmail.com> - 2011-07-13 08:47 -0700
  Re: Hungarian Notation and Java markspace <-@.> - 2011-07-13 09:23 -0700
  Re: Hungarian Notation and Java Roedy Green <see_website@mindprod.com.invalid> - 2011-07-13 15:33 -0700
  Re: Hungarian Notation and Java Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-07-14 18:45 +0200
    Re: Hungarian Notation and Java lewbloch <lewbloch@gmail.com> - 2011-07-14 17:30 -0700
  Re: Hungarian Notation and Java Travers Naran <tnaran@gmail.com> - 2011-07-17 22:06 -0700

csiph-web