Naming convention for property [closed]

╄→尐↘猪︶ㄣ 提交于 2020-01-24 10:57:15

问题


Which one is preferable or more clear?

public int FrozenRegionWidth { get; set; }

Or...

public int WidthOfFrozenRegion { get; set; }

回答1:


I'd say FrozenRegionWidth, otherwise you'll end up with a whole bunch of properties starting with 'WidthOf..'.

Having said that, shouldn't you have something like FrozenRegion.Width (another reason why I'd look for FrozenRegionWidth over WidthOfFrozenRegion)?




回答2:


I'd would prefer FrozenRegionWidth.

For more informations refer to .NET framework naming guidelines at http://msdn.microsoft.com/en-us/library/ms229012.aspx




回答3:


I'm not sure if it's a question for this community. I believe it must be a question for your team.

If I was only developer on a team and I have to choose a name, I would create a FrozenRegion class with Width property.




回答4:


FrozenRegionWidth is what is used everywhere. You just can't use

NameOfCustomer

instead of

CustomerName

This makes our variable short n sweet. You can't go on writing long sentences as variable names. And here you're creating an autoproperty. Remember that. It's more like a variable.




回答5:


But, consider the following scenario:

You are trying to look for the frozen region's width, but let say that you're not sure that it's called frozen region. Maybesome people call frozen region, another call it RegionThatIsFrozen (I know, lame example) or what ever: in that case, wouldn't it be easier for the programmer to type WidthOf and waits for the autocomplete to kicks in and choose the right one?




回答6:


Personally, i would prefere

public int FrozenRegionWidth { get; set; }



回答7:


I would favour whichever form proffers the more generic information first in the name.

That is to say, I want it so that when I'm looking at a the member list in intellisense they're grouped according to how I want to find them. If "FrozenRegion" is what's important to me than I want to name the related properties FrozenRegionWidth, FrozenRegionFoo, FrozenRegionBar. If I'm looking at "Width" I want WidthFrozenRegion, WidthFoo, WidthBar.

So it depends on your usage, but name from most generic to most specific.




回答8:


This question I asked on a similar vein may or may not help, it has indicators about noun choice.

To keep inline with the .NET BCL naming conventions I would use FrozenRegionWidth. It's unusual to include prepositions.

As mentioned above, FrozenWidth looks like a prime candidate for a struct/value type.



来源:https://stackoverflow.com/questions/861353/naming-convention-for-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!