I read an interesting article about boolean
arguments of functions:
The author argues that in many cases it is better to split a function that has a boolean
argument into two. This is because the use of boolean parameters increases the cyclomatic complexity
of the code.
So consider the following simple function:
let fbool (b: bool) (x: int) =
if b then x
else -x
Next, define a function defined from partial application, as follows:
let ftrue x = fbool true x
or equivalently
let ftrue = fbool true
Is the F# compiler smart enough to do what the author recommends, that is, is ftrue
as defined above a function that does not contain an if
statement and therefore does not contribute to cyclomatic complexity? Or does it contain an if
statement but happens to always choose the true
branch?
Aucun commentaire:
Enregistrer un commentaire