最佳命名为属性? [英] Best naming for a property?

查看:157
本文介绍了最佳命名为属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下哪三个选项,你会选择在C#中的属性名,为什么?

  1. YearToDateWages
  2. YTDWages
  3. YtdWages
解决方案

我将与我1 preFER去不是什么缩写,除非它是一个超级常见的缩写,这是荒谬的拼出来。像HyperTextTransferProtocolRequest是荒谬的拼出来,所以它是安全的缩写,作为Htt的prequest。这是一个有点主观的,但有疑问的时候,我倾向于用缩写。

如果你决定使用2或3,我可能会投3的基础上,从建议框架设计指南。它基本上说,对首字母缩略词是3个或更多字母长,你应该首字母大写和小写的休息。这是2个字母的缩写词有点暧昧......有些人preFER大写,如ID和一些preFER去与ID的所有字母。该指引是实际利用2个字母的缩写的所有字母,但那种相矛盾的准则3+字母缩写词,这样人们就两者兼得。

Which of the following three options would you choose for a property name in C#, and why?

  1. YearToDateWages
  2. YTDWages
  3. YtdWages

解决方案

I would go with 1. I prefer not to abbreviate anything, unless it's a super-common acronym that would be ridiculous to spell out. Something like "HyperTextTransferProtocolRequest" would be ridiculous to spell out, so it's safe to abbreviate that as "HttpRequest." It's a little subjective, but when in doubt, I tend to not abbreviate.

If you decide to go with 2 or 3, I'd probably vote for 3, based on the recommendations from the "Framework Design Guidelines." It basically says that for acronyms that are 3 or more letters long, you should capitalize the first letter and lower-case the rest. It's a little ambiguous on 2-letter acronyms... Some people prefer to capitalize all letters like "ID" and some prefer to go with "Id". The guideline is to actually capitalize all letters of a 2-letter acronym, but that kind of contradicts with the guideline for 3+ letter acronyms, so people do it both ways.

这篇关于最佳命名为属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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