我为什么不应该使用“匈牙利符号"? [英] Why shouldn't I use "Hungarian Notation"?

查看:108
本文介绍了我为什么不应该使用“匈牙利符号"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道匈牙利语指的是-提供有关变量,参数或类型的信息作为其名称的前缀.每个人似乎都在疯狂地反对它,即使在某些情况下,这似乎是一个好主意.如果我觉得正在传递有用的信息,为什么不把它放在可用的地方呢?

另请参见:人们是否使用现实世界中的匈牙利命名约定?

解决方案

大多数人以错误的方式使用匈牙利符号,并且得到错误的结果.

阅读Joel Spolsky撰写的精彩文章:使代码看起来不正确.

简而言之,匈牙利符号用变量名加上type(字符串)(系统匈牙利语)作为前缀是不好的,因为它没有用.

匈牙利注释法的作者所希望的,在变量名前加上变量kind(以乔尔的示例为例:安全字符串或不安全字符串),因此所谓的Apps Hungarian具有其用途,并且仍然很有价值.

I know what Hungarian refers to - giving information about a variable, parameter, or type as a prefix to its name. Everyone seems to be rabidly against it, even though in some cases it seems to be a good idea. If I feel that useful information is being imparted, why shouldn't I put it right there where it's available?

See also: Do people use the Hungarian naming conventions in the real world?

解决方案

Most people use Hungarian notation in a wrong way and are getting wrong results.

Read this excellent article by Joel Spolsky: Making Wrong Code Look Wrong.

In short, Hungarian Notation where you prefix your variable names with their type (string) (Systems Hungarian) is bad because it's useless.

Hungarian Notation as it was intended by its author where you prefix the variable name with its kind (using Joel's example: safe string or unsafe string), so called Apps Hungarian has its uses and is still valuable.

这篇关于我为什么不应该使用“匈牙利符号"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆