Geeks With Blogs

News

View Uri Goldstein's profile on LinkedIn

Add to Google
urig Tidbits from a .net life

I'm having a debate (with myself mostly) concerning the proper way to name private methods in C# projects.

For some forgotten reason, I have been accustomed to use camel casing when naming private methods - as opposed to using Pascal casing for public methods. Example:

private int getBlockInfo(int memberID) {...}
public int GetBlockInfo(int memberID) {...}

For me this seems very comfortable for differentiating between private "secret" methods within a class and public methods that are visible outside. This is similar in my mind to using camel case for private members while using Pascal case for matching public properties.

private int memberID;

public int MemberID { get { return memberID; } set { memberID = value; } }

Still, feeling somewhat insecure concerning the origin of this habit of mine, I consulted the C#  "Naming Guidelines" document buried deep within the MSDN. To my surprise the "Method Naming Guidelines" sections ignored the issue of private vs public methods and instructed that all methods should be named in Pascal case.

There is not doubt in my mind that I should follow Microsoft naming guidelines at all times. And yet there's this nagging feeling that my current habit rises not from whim but from logic. I must've seen this convention somewhere and adopted it. Do any of you, my trusted readers, know where it came from?

Posted on Sunday, January 7, 2007 10:45 AM | Back to top


Comments on this post: How to name Private Methods in C#?

# re: How to name Private Methods in C#?
Requesting Gravatar...
I have no ideas where that might have came from, but at one time I remember I was considering doing something similar. I debated that with myself for at least a month, before I gave up and decided to name both public and private methods in a similar way.

No matter what the MSDN guideline says, first and foremost you and your team must feel comfortable with the naming conventions.
Left by Jason Whitehorn on Jan 07, 2007 5:25 PM

# re: How to name Private Methods in C#?
Requesting Gravatar...
this is the coding standard bible for me: http://www.tiobe.com/standards/gemrcsharpcs.pdf

maybe it will help you...
Left by azazel on Mar 17, 2007 10:32 AM

# re: How to name Private Methods in C#?
Requesting Gravatar...
I have adopted the same habit and was convinced that this was the Microsoft method of doing things. Using FxCop to check the naming convention strengthend that believe. But I also recieved the conding conventiong stating that this is not the Microsoft way.
Left by Rainier on Mar 22, 2007 9:52 AM

# re: How to name Private Methods in C#?
Requesting Gravatar...
I think in this case we must follow the Microsoft way. And use camelcase to ONLY variables, field, parameters.
And BTW, even in field naming I prefix underscore "_" before the name.
Left by Khamza Davletov on Jan 07, 2008 4:09 AM

# re: How to name Private Methods in C#?
Requesting Gravatar...
I have the same feeling on that,I'm used to use Camel case on all naming conventions,after checked in msdn's naming conventions guide,I'm very surprised on that.
Left by bright.zhang on Apr 27, 2011 9:35 PM

Your comment:
 (will show your gravatar)


Copyright © urig | Powered by: GeeksWithBlogs.net