04. Functions
4.1 Implicit return by default
Functions return their last expression value. Use that as an implicit return.
If using any explicit returns, all returns in the function should be explicit.
4.2 GetX functions should be
Getters or functions with similar semantics that may fail to return valid values should be marked
<decides><transacts>
and return a non-option type. The caller should handle potential failure.An exception is functions that need to unconditionally write to a
var
. Failure would roll the mutation back, so they need to uselogic
oroption
for their return type.
4.3 Prefer Extension Methods to Single Parameter Functions
Use extension methods instead of a function with a single typed parameter.
Doing this helps Intellisense. By typing
MyVector.Normalize()
instead ofNormalize(MyVector)
it can suggest names with each character of the method name you type. For example:
Do not:
Last updated
Was this helpful?