Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard naming convention for self-identifiers in F#? [duplicate]

Regarding F# self-identifier's as in:

type MyClass2 =
   let data = 123

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

The F# class documentation says:

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

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

My question is, is there perhaps an unofficial standard of what to name the self-identifier? That is, while there may not be a prescriptive convention, is there a descriptive convention of what are F# programmers doing in the wild? this? x? self?

Update

Well looks like this may get closed, but the answer to the other question is hardly an answer as it's just showing multiple options which I'm already aware of. I'm looking for a consensus. Also, that question was asked in 2009 and there might not have been a consensus at that time, while there may be one now.

Also interesting is the book Expert F# 3.0 authored by Don Syme does not use a consistent self-identifier in the examples. Rather it seems to favor single letter self identifiers especially the letter x.

like image 832
User Avatar asked Mar 13 '13 07:03

User


People also ask

What is naming convention and identifiers?

In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation.

What is a naming convention and when is it used?

A naming convention is a convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: Allow useful information to be deduced from the names based on regularities.

What are the conventions followed in Java for naming identifiers?

All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). After the first character, identifiers can have any combination of characters. A keyword cannot be used as an identifier.

Why do we follow naming convention rules?

Unified Style Enhances Readability Imagine a large project with hundreds of developers who participate. If every developer decided to name variables and functions with their own style, the project is going to be a mess. Developers who follow the same naming convention across the project contribute to its readability.

What are the identifier naming conventions used in C programming languages?

In addition to the rules, there are many identifier naming conventions used throughout the .NET APIs. By convention, C# programs use PascalCase for type names, namespaces, and all public members.

Is the @ part of the identifier name?

The @ is not part of the identifier name. For example, @if declares an identifier named if. These verbatim identifiers are primarily for interoperability with identifiers declared in other languages. For a complete definition of valid identifiers, see the Identifiers topic in the C# Language Specification.

Is there a standard naming convention for code parts?

— Robert C. Martin The naming convention is a very contentious topic. Everyone has their own style when it comes to naming variables, functions, classes, and even documentation. There is no single or standard way to name your code parts.

What is an identifier in C++?

An identifier is the name you assign to a type (class, interface, struct, delegate, or enum), member, variable, or namespace. Valid identifiers must follow these rules: Identifiers must start with a letter, or _.


1 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 that is faulty because x does not explain what it is, and for one of the most used names in F# - the self identifier should be self-explanatory!

Some people also choose to write member __.Name when the self identifier is unnecessary. Those are usually the same people who make sure there are no unused identifiers (easy to do with --warnon:1182). Other people say that this is weird or that it leads to inconsistency - choose what you like.

like image 65
Ramon Snir Avatar answered Oct 11 '22 09:10

Ramon Snir