我终于做到了 - 匈牙利表示法 [英] I finally did it-- hungarian notation
问题描述
因此,在.NET工作了三年之后,我顽固地坚持了我的旧的
匈牙利语符号练习---我决定试图摆脱自己的
习惯。伙计,我得说这是解放!我喜欢它。
起初我在如何命名控件方面苦苦挣扎。我试着跟他们保持一些
符号...但我把它扔掉了!!!我现在将它们命名为好像
它们只是表格的属性(FirstNameLabel等)......它们是
ARE!...当我引用它们时我使用Me关键字(因为应该引用
a类的所有属性)。纯粹的快乐!
唉,我还是用m_指示私有类范围的变量。它有助于
将它们与属性区分开来并避免与属性碰撞
名称...因为,好吧,VB不像C#那样区分大小写!这导致了
问题,如下例所示:
私有firstName为字符串
公共属性FirstName()As String
获取
返回firstName
结束获取
设置(ByVal值为字符串)
firstName = value
结束集
结束物业
我建议任何坚持(你知道你在那里!)尝试一下。
就像从肩膀上抬起一个大重量。
So after three years of working in .NET and stubbornly holding on to my old
hungarian notation practices--- I resolved to try to rid myself of the
habit. Man, I gotta say that it is liberating!!! I love it.
At first I struggled with how to name controls. I tried to keep some sort of
notation with them... but I threw that away too!!! I now name them as if
they were simply properties of the form (FirstNameLabel, etc.)... which they
ARE!... and when I reference them I use the Me keyword (as all properties of
a class should be referenced). Pure joy!
Alas, I still use "m_" to indicate private class scoped variables. It helps
to set them apart from properties and with avoiding collisions with property
names... because, well, VB is not case sensitive like C#!!! This causes
problems as in the following example:
Private firstName As String
Public Property FirstName() As String
Get
Return firstName
End Get
Set(ByVal value As String)
firstName = value
End Set
End Property
I recommend that any hold outs (you know you''re out there!) give it a try.
It''s like a big weight is lifted from your shoulders.
推荐答案
从来没有去过匈牙利,但我个人更喜欢在所有对象前面添加一个
3字符代码,表示它是什么类型的对象。我开始用VB5的方式开始做这个了,但是现在在VB2005中它变得更加有用了,因为我不能问对象的类名再过......当我通过表格的控制集合循环
时,前3个字符确切地告诉我
它是什么。
Martin
" CMM" < cm*@nospam.com>在留言中写道
新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...
Never been to Hungary but I personally prefer to prefix all objects with a
3-character code which signifies what kind of object it is. I started doing
this in VB5 way back when but now in VB2005 it turns out to be even more
useful since I can''t ask the class name of an object anymore... When I loop
through a form''s control collection the first 3 characters tell me exactly
what it is.
Martin
"CMM" <cm*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
所以之后在.NET工作了三年,顽固地坚持我的古老的匈牙利记谱法 - 我决定试图摆脱自己的习惯。伙计,我得说这是解放!我喜欢它。
起初我在如何命名控件方面苦苦挣扎。我试着跟他们保持某种符号......但我也把它丢了!我现在将它们命名为
如果它们只是表单的属性(FirstNameLabel等)......它们就是它们......当我引用它们时我使用Me关键字(作为所有
应引用类的属性)。纯粹的快乐!
唉,我仍然使用m_指示私有类范围的变量。它有助于将它们与属性区分开来并避免与属性名称冲突...因为,嗯,VB不像C#那样区分大小写!这会导致问题,如下例所示:
私有firstName As String
公共属性FirstName()As String
获取
返回firstName
结束获取
设置(ByVal值为字符串)
firstName = value
结束集
结束属性
我建议任何坚持(你知道)你出去了!)试一试。
这就像是从你的肩膀上抬起一个巨大的重量。
So after three years of working in .NET and stubbornly holding on to my
old hungarian notation practices--- I resolved to try to rid myself of the
habit. Man, I gotta say that it is liberating!!! I love it.
At first I struggled with how to name controls. I tried to keep some sort
of notation with them... but I threw that away too!!! I now name them as
if they were simply properties of the form (FirstNameLabel, etc.)... which
they ARE!... and when I reference them I use the Me keyword (as all
properties of a class should be referenced). Pure joy!
Alas, I still use "m_" to indicate private class scoped variables. It
helps to set them apart from properties and with avoiding collisions with
property names... because, well, VB is not case sensitive like C#!!! This
causes problems as in the following example:
Private firstName As String
Public Property FirstName() As String
Get
Return firstName
End Get
Set(ByVal value As String)
firstName = value
End Set
End Property
I recommend that any hold outs (you know you''re out there!) give it a try.
It''s like a big weight is lifted from your shoulders.
"马丁" < x@y.com>在消息中写道
新闻:Oj ************** @ TK2MSFTNGP12.phx.gbl ...
"Martin" <x@y.com> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl...
从未去过匈牙利但是我个人更喜欢在所有对象前面添加一个
3字符代码,表示它是什么类型的对象。
这没问题 - 三个字母有17,000多种可能性,而
有
只有4,000框架中的-odd类...... ;-)
我开始以VB5的方式开始这样做,但现在在VB2005中,它变得更加有用,因为我可以''请问一个对象的班级名称
...
是什么让你这么想?
当我循环表格'' s控制收集前3个字符
告诉我它到底是什么。
Never been to Hungary but I personally prefer to prefix all objects with a
3-character code which signifies what kind of object it is.
That''s no problem - three letters gives 17,000-odd possibilities, and
there''s
only 4,000-odd classes in the Framework... ;-)
I started doing this in VB5 way back when but now in VB2005 it turns out
to be even more useful since I can''t ask the class name of an object
anymore...
What makes you think that?
When I loop through a form''s control collection the first 3 characters
tell me exactly what it is.
又有什么问题
每个ctl作为Me.Controls中的控件
如果TypeOf ctl是TextBox那么
。 。 。
ElseIf TypeOf ctl是ListBox然后
。 。 。
结束如果
下一页
??
此致,
Phill W.
And what''s wrong with
For Each ctl As Control in Me.Controls
If TypeOf ctl Is TextBox Then
. . .
ElseIf TypeOf ctl Is ListBox Then
. . .
End If
Next
??
Regards,
Phill W.
" CMM" < cm*@nospam.com> schrieb:
"CMM" <cm*@nospam.com> schrieb:
因此,在.NET工作了三年并且顽固地坚持我的古老的匈牙利符号练习之后 - 我决定试图摆脱自己的习惯。伙计,我得说这是解放!我喜欢它。
So after three years of working in .NET and stubbornly holding on to my
old hungarian notation practices--- I resolved to try to rid myself of the
habit. Man, I gotta say that it is liberating!!! I love it.
好吧,我不使用类型前缀(系统匈牙利语),因为我使用''选项
严格在''大部分时间。但是,我在处理
后期绑定时使用类型前缀(变量类型为''Object'')。另外,我使用''m_''
前缀来标记私有字段,我倾向于使用Apps Hungarian,因为它使用严格类型的语言仍然有意义。 b。 br />
在旁注:我仍然拒绝使用驼峰案,因为
< URL:http://dotnet.mvps.org/中列出的原因DOTNET /物品/驼峰/> (德国文章!)。
-
MS Herfried K. Wagner
MVP< URL:http:// dotnet.mvps.org/>
VB< URL:http://classicvb.org/petition/>
Well, I do not use type prefixes ("Systems Hungarian") because I use ''Option
Strict On'' most of the time. However, I use type prefixes when dealing with
late binding (variables typed as ''Object''). Additionally I use the ''m_''
prefix to mark private fields, and I tend to use Apps Hungarian because it
still makes sense in strictly-typed languages.
On a side note: I still refuse to use camel case for the reasons listed in
<URL:http://dotnet.mvps.org/dotnet/articles/camelcase/> (German article!).
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
这篇关于我终于做到了 - 匈牙利表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!