fsharp / fsharp/fslang-design

[style-guide] prefer leading rather than trailing operators

Open
#687 10 comments 10 reactions 0 assignees View on GitHub
style-guide
Dominant language
F#
Stars
557
Forks
149
Avg merge
4d 13h
Merged PRs (30d)
2

Description

This is a suggestion regarding position of operators in chained expressions

starting from:

```fsharp
if
long-thing &&
another-long-thing &&
another-long-thing &&
another-long-thing
then
```

I generally feel it is actually better (especially with long things) to put the operator in a leading position on the next line:

```fsharp
if
long-thing
&& another-long-thing
&& another-long-thing
&& another-long-thing
then
```

The same rule could be extended for `,` as well.

```fsharp
let a =
long-thing,
another-long-thing,
another-long-thing
```

```fsharp
let a =
long-thing
, another-long-thing
, another-long-thing
```

Note that F# users tend to use `|>` operator in such manner.

Also, most languages using "fluent notation" (chaining method calls), would put the `.` operator in leading position of next line

```fsharp
a
.Something()
.AnotherThing()
```

I've consistently felt it is more readable, easier to extend code, in many languages, using this type of positioning.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.