I have been trying to incorporate \() into code more and wonder if the style guide would benefit from including some do's/don'ts about using it. For example, here are some rough rules I've been following:
Use \() if and only if the function body fits on the same line (i.e., never use \() with a {-wrapped body)
Avoid using \() when assigning a function, i.e. rarely use foo <- \(...) [not prohibited since there are some cases where we can just squeeze a short wrapper function into one <=80-character line with \(), but using function() would require ballooning the definition to three lines to accommodate the {]
Prefer using \() with 0 or 1 arguments, occasionally 2, and rarely with ... unless it's the only argument
Avoid the parentheses-dense usage inside a pipe like x |> (\(...) ...)()
Yeah, I think we could include some advice along the lines of you should only use it for simple, single-expression anonymous functions. We should also suggest that you use it instead of ~.
I have been trying to incorporate
\()
into code more and wonder if the style guide would benefit from including some do's/don'ts about using it. For example, here are some rough rules I've been following:\()
if and only if the function body fits on the same line (i.e., never use\()
with a{
-wrapped body)\()
when assigning a function, i.e. rarely usefoo <- \(...)
[not prohibited since there are some cases where we can just squeeze a short wrapper function into one <=80-character line with\()
, but usingfunction()
would require ballooning the definition to three lines to accommodate the{
]\()
with 0 or 1 arguments, occasionally 2, and rarely with...
unless it's the only argumentx |> (\(...) ...)()