Skip to content

Commit 7d8c808

Browse files
cartermpmairaw
authored andcommitted
Add pascal case and parameter section to naming guidelines in F# formatting guide (#5403)
* Add pascal case and parameter section to naming guidelines in formatting * Feedback per maira
1 parent d0f0dac commit 7d8c808

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/fsharp/style-guide/formatting.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,56 @@ let emailMyBossTheLatestResults =
468468
...
469469
```
470470

471+
### Use camelCase for parameters
472+
473+
All parameters should use camelCase in accordance with .NET naming conventions.
474+
475+
```fsharp
476+
module MyModule =
477+
let myFunction paramOne paramTwo = ...
478+
479+
type MyClass() =
480+
member this.MyMethod(paramOne, paramTwo) = ...
481+
```
482+
483+
### Use PascalCase for modules
484+
485+
All modules (top-level, internal, private, nested) should use PascalCase.
486+
487+
```fsharp
488+
module MyTopLevelModule
489+
490+
module Helpers =
491+
module private SuperHelpers =
492+
...
493+
494+
...
495+
```
496+
497+
### Use PascalCase for type declarations, members, and labels
498+
499+
Classes, interfaces, structs, enumerations, delegates, records, and discriminated unions should all be named with PascalCase. Members within types and labels for records and discriminated unions should also use PascalCase.
500+
501+
```fsharp
502+
type IMyInterface =
503+
abstract Something: int
504+
505+
type MyClass() =
506+
member this.MyMethod(x, y) = x + y
507+
508+
type MyRecord = { IntVal: int; StringVal: string }
509+
510+
type SchoolPerson =
511+
| Professor
512+
| Student
513+
| Advisor
514+
| Administrator
515+
```
516+
517+
### Use PascalCase for constructs intrinsic to .NET
518+
519+
Namespaces, exceptions, events, and project/`.dll` names should also use PascalCase. Not only does this make consumption from other .NET languages feel more natural to consumers, it's also consistent with .NET naming conventions that you are likely to encounter.
520+
471521
### Avoid underscores in names
472522

473523
Historically, some F# libraries have used underscores in names. However, this is no longer widely accepted, partly because it clashes with .NET naming conventions. That said, some F# programmers use underscores heavily, partly for historical reasons, and tolerance and respect is important. However, be aware that the style is often disliked by others who have a choice about whether to use it.

0 commit comments

Comments
 (0)