开发者

Do you use Hungarian notation for control names? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I totally agree that we should not use Hungarian Notation to name variables. But it seems that Hungarian Notation is still useful to 开发者_JAVA百科name controls (especially Winform controls). Consider these:

GridView grvUsers
TextBox txtPassword

etc...

I really doubt that should we avoid Hungarian notation in this case? If should, which is alternative solution to name controls?


Regardless of whether it is right or wrong, it is still the defacto standard to use Hungarian Notation for naming controls, and it seems very out-of-place not to adopt it. In the same way that methods in .NET languages use Pascal Casing (while in most other languages it is frowned upon), stepping outside of the accepted conventions for the environment you're working in just tends to make your code look even more out-of-place.

I am personally in favour of the practise, as it helps to distinguish class members which are part of the user-interface (view) from those members which are part of the code-behind (model/controller). If the control variables are given similar-looking names to those used to store data, state, etc then I feel as though it is harder to resist the temptation to tightly couple the two. Of course, a more distinct separation of logic would overcome that as well.

Nevertheless, Hungarian Notation leaves no doubt as to which variables are part of the user-interface, and also makes clear as to their type and function, both in the designer and the code editor.


I usually name controls according to what they are, but with more Englishy names. Like, i'll name a label control for a first name box, "FirstNameLabel", and the textbox "FirstNameBox". It wasn't even intentional; i just noticed one day i was doing it, and it made sense to keep doing it.

I think i'm gonna call this "American notation".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜