Skip to content

The section on "Formatting Whitespace in Expressions" in the F# coding guidelines is misguiding #9091

@abelbraaksma

Description

@abelbraaksma

I think we ought to mention that whitespace is sometimes necessary and since this is a guideline, we should enumerate the cases to create consistency.

I suggest we add something like this (text to be defined):

  • Around infix operators, whitespace should be used: 1 + 3, not 1+3. This avoids problems like x -1 which is a different expression entirely to x - 1.
  • Mention that whitespace following a function identifier can be necessary. myFunction() is different from myFunction (). The advice should be that in general, when it is a .NET member function, no space is used after the identifier. When it is a curried function, or a standard F# function, a space is required. While there are cases where both syntaxes yield the same result, this is the place to give a guideline, which hopefully avoids common pitfalls encountered by newcomers.
  • After prefix operators, no space should be used. Good: x = -1, bad: x = - 1.
  • In operator definitions, a space should be used. This prevents certain compile errors, and consistency is key here. Good: ( !. ) y = y, bad: (!.) y = y. (i.e., a compile error will happen when an operator starts with a * and you don't use a space).
  • Around -> there should always be a space. Good function X -> y, bad: function X->y.

... anything else I've missed?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions