Records
How do you prefer to declare records which have many fields?
The guidelines here GitHub - G-Research/fsharp-formatting-conventions: G-Research F# code formatting guidelines specify this as preferred:
type PostalAddress =
{
Address : string
City : string
Zip : string
}
But the book “Stylish F#” says this is better:
type PostalAddress = {
Address : string
City : string
Zip : string }
While the book “Get Programming with F#” uses:
type PostalAddress =
{ Address : string
City : string
Zip : string }
And there seems to be another suggestion here: https://learn.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting
type PostalAddress = {
Address : string
City : string
Zip : string
}
I had a quick look in the Fantomas code repo on GitHub and it seems to have a mix.
I can see some pros and cons for each but I was wondering which is more prevalent/preferred.
DUs
Along the same lines, I am finding myself having to define DUs where the fields have very long names and so can’t be easily held on one line, for instance:
type ThingWithLongNameDataRequest =
| Create
| Delete of
UserDefinedThingWithLongName : UserDefinedThingWithLongName
| Rename of
UserDefinedThingWithLongName : UserDefinedThingWithLongName
* NewName : string
| UpdateSomethingReallyImportant of
UserDefinedThingWithLongName : UserDefinedThingWithLongName
* NewSomethingReallyImportant : int
| UpdateSequenceType of
UserDefinedThingWithLongName : UserDefinedThingWithLongName *
NewSequenceType : ThingWithLongNameSequenceType
| UpdateSegmentSomethingOrOther of
UserDefinedThingWithLongName : UserDefinedThingWithLongName *
ThingWithLongNameSegment : ThingWithLongNameSegment *
NewSomethingOrOther : SomethingOrOther
Is it better to put the ‘*’ at the start of the field definition (as with Rename above) or the end (as with the last two above)?
Again, I can see some pros and cons for each but was wondering if there were any major problems with either.