When should we use the ..
Record Wildcards operator to implicitly bind choice arguments, and we should we explicitly enumerate them? In other words, choose between:
- Implicit:
let splitAmount = 80.0 exerciseCmd iouCid Iou_Split with ..
- Explicit:
let splitAmount = 80.0 exerciseCmd iouCid Iou_Split with splitAmount
Note: Let’s suppose the arguments (splitAmount
) are already bound for some reason (contract field, choice argument, code cleanness etc), and let’s not consider here the otherwise nice solution: exerciseCmd iouCid Iou_Split with splitAmount = 80.0
.
Some arguments are as follows:
Implicit (using ..
)
- Convenient (you need to type less, think about arguments less)
- Easier to refactor (less editing needed when arg list changes)
- Shorter code: better signal/noise ratio
- Clean code should limit scope where variables can come from - e.g. a long function is a code smell
Explicit
- Explicit is cleaner than implicit according to some guidelines (see also Zen of Python, C++ Core Guidelines)
- Easier to track in the IDE/editor where a variable is used
- Easier to find out what the choice arguments are (no need to open the choice)
- Passing many arguments could already be a code smell, so the code might already need refactoring (giving more structure)
- Slightly safer: harder to unintentionally pass a variable
Note: I only found a bit of documentation describing ..
on docs.daml.com.