At 09:28 AM 7/21/2006, Carl Reynolds wrote:
I think Hungarian notation should be avoided in any language, but is
seems to me that it just becomes an extra annoyance with no added
value in a typeless language like JavaScript.
Stating that Hungarian Notation "should be avoided" sounds like you
know of some deleterious effects it has on software development. Is
this the case or is it merely a matter of personal taste for
you? For a few pro & con arguments see
http://en.wikipedia.org/wiki/Hungarian_notation#Criticisms
I believe anything that helps a programmer write better code is a
valuable tool for that individual. I started using Hungarian
Notation consistently a couple of years ago and I find it helps me
write tighter code. Typing my variables helps me remember their
purpose and the range of values I'm using them to store, and makes it
less likely that I'll run afoul of asymmetrical rules of usage which
exist even in ostensibly "typeless" languages such as JavaScript.
In JavaScript, while conversion between types occurs silently, those
types do exist in the underlying language structure -- hence the
operator 'typeof':
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Special_Operators:typeof_Operator
JavaScript operators can have different effects on different types of
values -- for example, compare the use of + to join strings with
strings, strings with numerics, and numerics with numerics:
"37" - 7 // returns 30
"37" + 7 // returns "377"
37 + 7 // returns 42
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Values#Data_Type_Conversion
Also, methods vary significantly from one type of object to another;
to use JavaScript without regard to type would mean avoiding objects
such as Math, String, and RegExp and their methods. I do use these
objects, and I help myself remember the type of object by prefixing
the variable name.
I can see that type-notating variables would be an annoyance if one
used the same variable to store different types of value in the
course of a single program. I don't do this, so perhaps it's more a
difference in programming style than notation that we're pointing to here.
Regards,
Paul
******************************************************
The discussion list for http://webstandardsgroup.org/
See http://webstandardsgroup.org/mail/guidelines.cfm
for some hints on posting to the list & getting help
******************************************************