@@ -2,56 +2,7 @@ We prefer the latest F# 9 features over the old syntax
22
33Prefer ` voption ` over ` option `
44
5- Prefer ` task ` CE over ` async ` CE
5+ Prefer ` async ` CE over ` task ` CE
66
7- This is how you define a non-default F# class constructor:
8- ``` fsharp
9- type DerivedClass =
10- inherit BaseClass
11-
12- new (``arguments here``) as ``created object``
13- =
14- // create any objects used in the base class constructor
15- let fieldValue = ""
16- {
17- inherit
18- BaseClass (``arguments here``)
19- }
20- then
21- ``created object``.otherField <- fieldValue
22-
23- [<DefaultValue>]
24- val mutable otherField : FieldType
25- ```
26-
27- Always prefer F# class initializers over property assignment! ** You absolutely must use F# class initializers instead of property assignment** !
28-
29- Class declaration:
30- ``` F#
31- type MyClass (someConstructorParam : string) =
32- member ReadOnlyProperty = someConstructorParam
33-
34- member val MutableProperty1 = "" with get, set
35- member val MutableProperty2 = "" with get, set
36- ```
37-
38- Wrong:
39- ``` F#
40- let myClass = MyClass("some value")
41- myClass.MutableProperty1 <- "new value"
42- myClass.MutableProperty2 <- "new value"
43- ```
44-
45- Right:
46- ``` F#
47- let myClass =
48- MyClass(
49- // constructor parameters go first without names
50- "some value",
51- // then mutable properties go next with names
52- MutableProperty1 = "new value",
53- MutableProperty2 =
54- // operations must be placed into parentheses
55- (5 |> string)
56- )
57- ```
7+ Prefer idiomatic F#, that is, code that favors composition over inheritance,
8+ and leans to immutability (pure functions, usage of thread-safe collections, etc.)
0 commit comments