What are the naming conventions that you use while

2019-02-15 06:55发布

What are the naming conventions that you use while coding?

7条回答
Root(大扎)
2楼-- · 2019-02-15 07:25

I hope we will not discuss prefixes for field names and brace styles here :)

Here is my bible for .NET:

alt text http://ecx.images-amazon.com/images/I/51HT7RDZW7L._SL500_AA240_.jpg

Also MSDN gives solid guidelines.

Another useful source is MS Internal Coding Guidelines

查看更多
太酷不给撩
3楼-- · 2019-02-15 07:27

Pick one at be consistent. Changing name styles leads to confusion.

查看更多
Deceive 欺骗
4楼-- · 2019-02-15 07:30

To add on to the answer from @Aku authors of the Framework Design Guidelines have published on online digest version of their guidelines, with an emphasis on naming convetions.

Framework Design Guidelines Digest v2

Download here

Consistency is key. Depending on the size of your development team, using a consistent and documented convetion will make it easier to pick up someone elses code and for others to pick up your own code.

查看更多
太酷不给撩
5楼-- · 2019-02-15 07:32

I use a combination of Hungarian, camel case, and other rules I come up with in the beginning of a project. Like right now:

  • Methods are upper case (DoThis)
  • variables are camel case (thisThing)
  • page level variables are prefaced with _ (_thisWorksEverywhere)
  • regions are all lower case (#region foreign properties)
  • Properties and Objects are uppercase (Object.Property)
  • Foreign properties are prefaced by _ (Object._ForeignGroups)
  • Controls are Hungarian to an extent, like (txtTextBox) and (rptRepeater). I'm not too strict as to what's customary because "Watermark" can be wm or wk or whatever, as long as they all match each other accross my application.

...etc. Some things are standard, others are up to interpretation, but the most important thing is consistency across your application.

查看更多
Evening l夕情丶
6楼-- · 2019-02-15 07:34

Hungarian notation can be used. I don't bother myself, but I give various things (variables, controls, etc.) sensible names.

For example, I use a Hungarian-style prefix for control names such as txt for TextBoxes, btn for Buttons, pic for PictureBoxes, lbl for Labels, etc. That helps to easily identify what a control is.

For function names I try and use sensible explanatory names, but nothing with any particular rules. For variable names again I just use explanatory names but nothing special.

查看更多
可以哭但决不认输i
7楼-- · 2019-02-15 07:36

Here's a list of general naming conventions from MSDN.

I tend to just go-with-the-flow, however. Whatever standards are currently in place, it's usually easiest to just go with them and maybe slowly shift it over time. It's not really practical to just come into a project with your own idea of "standards" and try to implement them.

It doesn't REALLY matter what standards are used, imo -- just that there are some and people know what they are.

查看更多
登录 后发表回答