Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private method naming convention [closed]

Is there a convention for naming the private method that I have called "_Add" here? I am not a fan of the leading underscore but it is what one of my teammates suggests.

public Vector Add(Vector vector) {     // check vector for null, and compare Length to vector.Length     return _Add(vector); }  public static Vector Add(Vector vector1, Vector vector2) {     // check parameters for null, and compare Lengths     Vector returnVector = vector1.Clone()     return returnVector._Add(vector2); }  private Vector _Add(Vector vector) {     for (int index = 0; index < Length; index++) {         this[index] += vector[index];     }     return this; } 
like image 981
jason Avatar asked Dec 20 '08 23:12

jason


People also ask

What naming convention should be used for method names?

Interface names should be capitalized like class names. Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter.

How do you name a private variable in C#?

Use camel casing ("camelCasing") when naming private or internal fields, and prefix them with _ . When editing C# code that follows these naming conventions in an IDE that supports statement completion, typing _ will show all of the object-scoped members.

How do you name a private variable?

We have to start a variable name with a double underscore to represent it as a private variable (not really). Example:- one, two, etc..,. As we already said the variables whose names start with a double underscore are not private.


1 Answers

I've never seen any coding convention in C# that distinguished between public and private methods. I don't suggest doing it, since I don't see the benefit.

If the method name conflicts with public methods, it’s time to become more descriptive; if, as in your case, it contains the actual method implementation for the public method, one convention is to call it *Impl. I.e. AddImpl in your case.

like image 79
Konrad Rudolph Avatar answered Oct 13 '22 03:10

Konrad Rudolph