为什么匈牙利符号被遗弃? [英] Why has hungarian notation been abandoned?

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

问题描述

有没有人知道微软放弃Hungarina的原因

C#中的表示法?


我发现它在C ++中非常有用。我喜欢这种风格:


常数:MY_CONSTANT

方法:myMethod()

类:MyClass

变量:iMyInteger


无论如何,我对这种新风格并不是很疯狂,但想知道是否有一个好的

理由让他们将所有功能和班级而不使用

匈牙利表示法?

Does anyone know the reasoning for Microsoft abandoning Hungarina
Notation in C#?

I have found it very usefull in C++. I like this style:

constant: MY_CONSTANT
methos: myMethod()
class: MyClass
variable: iMyInteger

Anyway I''m not crazy about the new style but wonder if there is a good
reason for them capitalizing all functions and classes and not using
hungarian notation?

推荐答案



" Phill" < WA ******** @ yahoo.com>在消息中写道

news:ac ************************** @ posting.google.c om ...

"Phill" <wa********@yahoo.com> wrote in message
news:ac**************************@posting.google.c om...
有没有人知道微软在C#中放弃Hungarina
表示法的原因?
Does anyone know the reasoning for Microsoft abandoning Hungarina
Notation in C#?



IMO匈牙利语版本(或以其他方式用

其类型和范围的指示)在过程语言中很有用,

倾向于使用大量全局变量,而且语言较少

比类型安全。有必要记住,当用C语言编程时,无论变量是指针还是整数,如果是一个指针,一个指针,指向

到什么。


考虑一系列双打。


一个常见的C语言,如


*(pDblLocation ++)。相比之下,在C#


位置[i]


是可读的。


David


IMO Hungarian notaion (or otherwise decorating variable names with
indications of their type and scope) is helpful in procedural languages,
which tend to use a lot of global variables, and in languages which are less
than type-safe. It is necessary to rememeber, when programming in C,
whether a variable is a pointer or an integer, and if a pointer, a pointer
to what.

Consider an array of doubles.

A common C idiom like

*(pDblLocation++)

is very hard to read without hungarian notation. In contrast, in C#

locations[i]

is quite readable as is.

David


" Phill" < WA ******** @ yahoo.com>在消息新闻中写道:ac ************************** @ posting.google.c om ...
"Phill" <wa********@yahoo.com> wrote in message news:ac**************************@posting.google.c om...
无论如何,我对这种新风格并不感到骄傲,但想知道是否有一个很好的理由让他们将所有功能和课程资本化而不使用匈牙利语符号?
Anyway I''m not crazy about the new style but wonder if there is a good
reason for them capitalizing all functions and classes and not using
hungarian notation?




开发人员现在可以将任何标识符带入立即窗口并且

写入,


? identifier.GetType()


和瞧,你得到变量的类型。不自然的,不可发音的

前缀不会增加任何价值。我不知道一个

AutomotivePartSKU类型对象的匈牙利语前缀应该是什么(它可能是什么东西

像''obj''一样荒谬,并不能帮我把它分开一架飞机 -

PartSKU一点),我也不在乎。 CLR中的所有对象都知道什么是

它们的类型,与C不同。


我的建议不是教条地坚持匈牙利符号;认识

为什么过去有必要,以及为什么现在不再需要

.

Derek Harmon



Developers can now take any identifier into the Immediate Window and
write,

? identifier.GetType()

and voila, you get the type of the variable. Unnatural, unpronounceable
prefixes add no value. I don''t know what the Hungarian prefix for an
AutomotivePartSKU-typed object should be (it''s probably something
ridiculous like ''obj'', which doesn''t help me tell it apart from an Aircraft-
PartSKU one bit), and I don''t care. All objects in the CLR know what
Type they are, unlike in C.

My advice is not to dogmatically cling to Hungarian notation; recognize
why it was necessary in the past, and why it''s no longer necessary in the
present.
Derek Harmon


Phill写道:
有没有人知道微软在C#中放弃Hungarina
表示法的原因?

我发现它在C ++中非常有用。我喜欢这种风格:

常数:MY_CONSTANT
方法:myMethod()
类:MyClass
变量:iMyInteger

无论如何我'我对这种新风格并不感到骄傲,但想知道是否有一个很好的理由让他们将所有功能和课程资本化而不使用匈牙利语符号?
Does anyone know the reasoning for Microsoft abandoning Hungarina
Notation in C#?

I have found it very usefull in C++. I like this style:

constant: MY_CONSTANT
methos: myMethod()
class: MyClass
variable: iMyInteger

Anyway I''m not crazy about the new style but wonder if there is a good
reason for them capitalizing all functions and classes and not using
hungarian notation?




好​​笑 - 几天前在ASP.NET小组中就提出过这个问题,所以我会告诉我b $ b转发我当时写的东西:

嗯,HN在标识符的名称中使用前缀,具体取决于标识符的

类型。在具有多态性的真实OO环境中,确切的类型通常是未知的(只是想到对象工厂只返回

接口类型)。实际上,大多数时候你甚至不关心

真实类型,只要该对象符合某种接口合同

(通过实现一个接口或从其他类继承)。


接下来,可能有数千种类型 - 这可能意味着使用* a

很多*的前缀。哦,一旦我需要更改类型,我必须使用该类型重命名所有

标识符。嘿,更糟糕的是,如果它是可见的改变

喜欢


public int Foo(int someInt)

to

public long Foo(如果您正在使用我的Foo()

方法 - 任何变量,你会想要改变你的代码。保存Foo'返回值的代码将使用

错误的前缀。


更不用说所有那些没有意义的经典HN前缀了。 NET在

全部 - l,p,sz,...


干杯,


-

Joerg Jooss
jo ********* @ gmx。网



Funny -- this was asked in the ASP.NET group just some days ago, so I''ll
repost what I''ve written back then:
Well, HN uses prefixes in an identifier''s name depending on the identifier''s
type. In a true OO environment featuring polymorphism, the exact type is
quite often unknown (just think of object factories that simply return
interface types). Actually, most of the time you don''t even care abut the
real type, as long as the object complies to some sort of interface contract
(by implementing an interface or inheriting from some other class).

Next, there are potentially thousands of types -- which could mean using *a
lot* of prefixes. Oh, and once I need to change a type, I have to rename all
identifiers using that type. Hey, even worse, if it''s a "visible" change
like

public int Foo(int someInt)
to
public long Foo(long someLong),

you would want to change your code as well, if you''re using my Foo()
method -- any variable in your code holding Foo''s return value will use the
wrong prefix otherwise.

Not to mention all those classic HN prefixes that make no sense in .NET at
all -- l, p, sz, ...

Cheers,

--
Joerg Jooss
jo*********@gmx.net


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

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