views:

194

answers:

10

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

  1. YearToDateWages
  2. YTDWages
  3. YtdWages
+2  A: 

I think the first one is best because it is self descriptive.

npinti
A: 

I would opt for the full name rather than one featuring an acronym. It is more descriptive, and while "YTD" may be obvious to some, it might not be to everyone. YearToDate is not excessively long and the meaning is clear.

Anthony Pegram
Does it need to be obvious to everyone, or only the people in the business maintaining and using the software?
Lance Fisher
@Lance: It should be sufficient that it is obvious to the people who maintain and work with the code. However, that doesn't mean an abbreviation is a good idea; think of people new to the source code who might not yet be used to the abbreviation. It is safer to type the full name if there can be even the slightest doubt of confusion; auto-completion means that you don't really need to type the full name when using it anyway.
Michael Madsen
+13  A: 

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.

Andy White
"Id" is an abbreviation of "Identity", not an acronym. That's why I prefer "Id" over "ID".
Lance Fisher
+5  A: 

I would use YearToDateWages, because without that being in the list I wouldn't know what you were talking about.

See also the general naming guidelines on MSDN:

In general, you should not use abbreviations or acronyms. These make your names less readable. Similarly, it is difficult to know when it is safe to assume that an acronym is widely recognized.

For capitalization rules for abbreviations, see Capitalization Conventions.

Do not use abbreviations or contractions as parts of identifier names.

For example, use OnButtonClick rather than OnBtnClick.

Do not use any acronyms that are not widely accepted, and then only when necessary.

Emphasis in original.

Mark Byers
+2  A: 

Microsoft suggested naming convention rule out #2

anything with > 2 acronym letters should be Xxx not XXX

but 2 should be XX

I like less typing so I would go with YtdWages

pm100
+1  A: 

It depends.

If you are making a library that will see external use, the .NET Framework Design Guidelines say that #1 is preferred.

If it's an internal application/library, then I recommend using the format that is consistent with your teams development standard.

Alan
A: 

Is there a reason why you would not use the first one?

It is not only for others; if you have to change something in your own code 2 years later, good, descriptive names will help you.

Ra
+3  A: 
bool ShouldIUseAbbreviate(string abbreviate_)
{
  foreach (var peer in myPeers)
  {
    if (!peer.CanGetTheMeaningWithinOneSecond(abbreviate_))
    {
      return false;
    }
  }

  return true;
}
Jerry Liu
syntax error at `my Peers` :)
Earlz
Fixed. Thanks. :-)
Jerry Liu
+1 for writing your answer in code! :)
Lance Fisher
+1 but your method should have been called bool SIUA(string _abbr)
Daniel Dyson
A: 

The .Net framework seems to follow mostly #1. So I would stick with it. Abbreviations should be avoided except where extremely commonly known at the class level. Of course for local(function) variables this is much less strict and I would say that abbreviations and short names are much more appropriate so as to make the code smaller and more concise.

Examples of good abbreviations are XML and HTTP. Who is seriously going to write

string x=myobject.HyperTextMarkupLanguageOutput;
Earlz
A: 

I vote for number 1 as well.

There will be very few times when you do NOT want a descriptive name. Visual Studio will assist you with the long names.

Semi off topic note: If you cant find a suitable name... perhaps the planned usage is not that clear after all ;)

Jonas Montonen