Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does it make sense to use Hungarian notation prefixes in interpreted languages? [closed]

First of all, I have taken a look at the following posts to avoid duplicate question.

https://stackoverflow.com/questions/1184717/hungarian-notation
Why shouldn't I use "Hungarian Notation"?
Are variable prefixes (“Hungarian notation”) really necessary anymore?
Do people use the Hungarian Naming Conventions in the real world?

Now, all of these posts are related to C#, C++, Java - strongly typed languages.
I do understand that there is no need for the prefixes when the type is known before compilation.
Nevertheless, my question is:

Is it worthwhile to use the prefixes in interpreter based languages, considering the fact that you cant see the type of the object before runtime?

Edit: If someone can make this post a community wiki, please do. I am hardly interested in the reputation (or negative reputation) from this post.

like image 241
Andrey Rubshtein Avatar asked Jan 09 '12 16:01

Andrey Rubshtein


People also ask

Should you use Hungarian notation?

Hungarian Notation can be useful in languages without compile-time type checking, as it would allow developer to quickly remind herself of how the particular variable is used. It does nothing for performance or behavior. It is supposed to improve code readability and is mostly a matter a taste and coding style.

Why is Hungarian notation obsolete?

The Hungarian notation is redundant when type-checking is done by the compiler. Compilers for languages providing strict type-checking, such as Pascal, ensure the usage of a variable is consistent with its type automatically; checks by eye are redundant and subject to human error.

Why is it called Hungarian Notation?

A variable naming convention developed by CharlesSimonyi at Microsoft. The word "Hungarian" is used to describe either Simonyi's original nationality or the appearance of the variables, or both (I forget) (he is Hungarian, for what it's worth).

What is m_ in C#?

As stated in the other answers, m_ prefix is used to indicate that a variable is a class member. This is different from Hungarian notation because it doesn't indicate the type of the variable but its context.


1 Answers

The reason Hungarian notation conveying type ("systems Hungarian") is frowned upon in Python is simple. It's misleading. A variable might be called iPhones (the integer number of phones, maybe :-) but because it's Python, there's nothing at all to keep you from putting something other than an integer into it! And maybe you will find you need to do that for some reason. And then all the code that uses it is very misleading to someone trying to understand it, unless of course you globally change the name of the variable.

This notation was intended to help you keep track of variable types in statically-typed languages and was arguably useful for a time. But it's obsolete now, even for statically typed languages, given the availability of IDEs that do the job in a much better way.

like image 111
kindall Avatar answered Sep 28 '22 08:09

kindall