Is there a standard naming convention for identifiers in F #?

Regarding the F # self-identifier, as in:

type MyClass2 = let data = 123 member whateverYouWant.PrintMessage() = printf "MyClass2 with Data %d" data 

F # class documentation :

Unlike other .NET languages, you can name the identifier self as you want; You are not limited to names such as self, Me, or this.

(The answer to the question, What are the advantages of such flexible "self-identifiers" in F #, explains the possible usefulness of this.)

My question is: is there perhaps an unofficial standard for what to call a self-identifier? That is, although there may not be a prescriptive agreement, is there a descriptive agreement on what F # programmers do in the wild? this ? x ? self ?

Update

It looks good that this may close, but the answer to another question is unlikely to be the answer, as it just shows a few options that I already know about. I am looking for consensus. In addition, this question was asked in 2009, and at that time there might not have been consensus, although it may be now.

Also interesting is the Expert F # 3.0 book by Don Sime, which does not use a consistent self-identifier in the examples. Rather, it looks like single letter identifiers, especially the letter x .

+7
source share
3 answers
 type MyClass2 as self = let data = 123 let privatePrintMessage() = self.PrintMessage() member this.PrintMessage() = printf "MyClass2 with Data %d" data 

Some people use member x.Name , but this is erroneous because x does not explain what it is, and for one of the most used names in F # - the identifier itself must be self-evident!

Some people also prefer to write member __.Name when the identifier itself is not needed. Usually these are the same people who are sure that there are no unused identifiers (easy to do with --warnon:1182 ). Other people say that this is strange or that it leads to inconsistency - choose what you like.

+7
source

There are several options: people often write this or self or x . I think x is probably the least descriptive, but it is used quite often - maybe this is wrong! Another good option is to use an identifier that refers to the class name (e.g. person or point ), because it is pretty informative.

 type Point(x:float, y:float) = member point.X = x member point.Y = y 

But I agree that it feels a little redundant when you are not really using self-esteem. So using __ makes sense. I think it is a little unfortunate that you cannot use just the usual (single) _ .

So, in general, there is apparently not a single recommended standard, but there are several common patterns.

+3
source

Another answer (if you prefer):

No, there is no standard naming convention for self-identifiers. You must choose one for each project and enforce it.

+1
source

All Articles