views:

247

answers:

6

I'm creating a C# library and am going to be prefix most of the public classes with the protocol they use (TCP, UDP, etc) and I came to a little dilemma: should it be TCPXxxx or TcpXxxx?

There doesn't seem to be a standard in the .NET framework (IPAddress versus TcpClient).

Which you would prefer when working with a lirbary: TCPXxxx or TcpXxxx?

+7  A: 

It should be TcpXxxx, by the design guidelines.

In the design guidelines, 2 letter acronyms are capitalized, all others are pascal cased.

From Framework Design Guidelines by Cwalina and Abrams:

  • Do capitalize both charaters of two-character acronyms, exception the first work of a camel-cased identifier.

    System.IO
    public void StartIO(Stream ioStream)

  • Do capitalize only the first character of acronyms with three or more characters, except the first word of a camel cased identifier.

MSDN has an abbrieviated, shorter version of this.

Reed Copsey
I think you mean PascalCased, not camelCased.
Joel Coehoorn
@Reed: Do you have a link? Not that I don't believe you, but I'd like to read it.
Samuel
@Samuel: I added it from the book itself... adding a link to msdn.
Reed Copsey
@Joel: Thanks for the note - just typed it wrong. Fixed now.
Reed Copsey
+1  A: 

Generally, when it's a 2-character prefix, leave it uppercase (IPAddress) and when it's 3 characters or more, Pascal-case the prefix (TcpXxxx).

There are a few exceptions to this rule (e.g., if a prefix is a proper name that's uppercase).

Joe Albahari
A: 

I know this is C# coding style but I prefer the Python PEP 8 Style

Note: When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus HTTPServerError is better than HttpServerError.

But when in Rome...consistent code is better which is why language style guides are a good idea.

Tanj
My personal philosophy is "Consistency over correctness".
Darren Clark
@Daren Totally agreed, but I like to express it more aptly as, "Consistency over Perfectionism" to avoid antagonists implying incorrectness as the only alternative.
Troy DeMonbreun
+2  A: 

I always like to imagine a theoretical process that converts WordsLikeThis to words-like-this, and imagine how the name in question would convert. Some examples:

TCPSocket -> t-c-p-socket
TcpSocket -> tcp-socket

Clearly the latter makes more sense.

jbg
A: 

You might consider putting these classes in a namespace called "TCP". If you do so, then your function/class names in that namespace will get shorter and clearer and you won't have to worry about this issue at all.

Aaron
That still has the problem with TCP vs. Tcp. And I want them as a prefix since I will be using terms like Client, Server, User, etc. I don't want someone to have to use a using alias to avoid a conflict.
Samuel
A: 

I know in eclipse I can quickly specify a type by using just the capitals letters of the type name so I prefer to under-capitalise rather than over-capitalise... I don't know if VS can do the same but it is fan-tastic.

CurtainDog