Always Shortcircuit

View Source
or and and should be replaced with orelse and andalso to ensure short-circuit evaluation.
Avoid
Expr1 or Expr2
Expr1 and Expr2Prefer
Expr1 orelse Expr2
Expr1 andalso Expr2Rationale
Although orelse and andalso are more verbose than or and and, they implement the behavior
expected by most developers, ensuring that Expr2 is evaluated only when Expr1 is:
false, fororelsetrue, forandalso
This also prevents:
- unnecessary computations
- potential errors when running the right-hand side of expressions based on prior assumptions
- right-associativity issues (e.g.
is_integer(X) and X > 0is not equivalent tois_integer(X) and (X > 0))
Options
- None.
Example configuration
{elvis_style, always_shortcircuit, #{}}