You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a long parenthesized expression containing addition or subtraction is followed by multiplication or division, the formatted result can be confusing. These are some examples:
fnmain(){let dv = (2.* m * l * dtheta * dtheta * theta.sin()
+ 3.* m * g * theta.sin()* theta.cos()
+ 4.* u
- 4.* b * v)
/ (4.*(M + m) - 3.* m * theta.cos().powi(2));let ddtheta = (-3.* m * l * dtheta * dtheta * theta.sin()* theta.cos()
- 6.*(M + m)* g * theta.sin()
- 6.*(u - b * v)* theta.cos())
/ (4.* l *(m + M) - 3.* m * l * theta.cos().powi(2));}
In all these examples, there is a multiplication or division of a parenthesized expression containing + or -. The * or / is indented by the same amount as the + or -, suggesting that it's at the same level, which by order of operations would mean that only the last expression would be multiplied/divided. It's not obvious that the + or - are in fact inside a parenthesized expression.
A relatively small change that would help would be to increase the indentation of the expressions inside the parentheses, like this:
fnmain(){let dv = (2.* m * l * dtheta * dtheta * theta.sin()
+ 3.* m * g * theta.sin()* theta.cos()
+ 4.* u
- 4.* b * v)
/ (4.*(M + m) - 3.* m * theta.cos().powi(2));let ddtheta = (-3.* m * l * dtheta * dtheta * theta.sin()* theta.cos()
- 6.*(M + m)* g * theta.sin()
- 6.*(u - b * v)* theta.cos())
/ (4.* l *(m + M) - 3.* m * l * theta.cos().powi(2));}
I think a better solution would be to make the parentheses more obvious by adding new lines after the opening parenthesis and before the closing parenthesis, with something like this:
fnmain(){let dv = (2.* m * l * dtheta * dtheta * theta.sin()
+ 3.* m * g * theta.sin()* theta.cos()
+ 4.* u
- 4.* b * v
) / (4.*(M + m) - 3.* m * theta.cos().powi(2));let ddtheta = (
-3.* m * l * dtheta * dtheta * theta.sin()* theta.cos()
- 6.*(M + m)* g * theta.sin()
- 6.*(u - b * v)* theta.cos()) / (4.* l *(m + M) - 3.* m * l * theta.cos().powi(2));}
Although doing so is not necessary for clarity, if the closing parenthesis is moved to a new line, we could eliminate some of the extra new lines, so the middle examples would become this:
When a long parenthesized expression containing addition or subtraction is followed by multiplication or division, the formatted result can be confusing. These are some examples:
In all these examples, there is a multiplication or division of a parenthesized expression containing
+
or-
. The*
or/
is indented by the same amount as the+
or-
, suggesting that it's at the same level, which by order of operations would mean that only the last expression would be multiplied/divided. It's not obvious that the+
or-
are in fact inside a parenthesized expression.A relatively small change that would help would be to increase the indentation of the expressions inside the parentheses, like this:
I think a better solution would be to make the parentheses more obvious by adding new lines after the opening parenthesis and before the closing parenthesis, with something like this:
Although doing so is not necessary for clarity, if the closing parenthesis is moved to a new line, we could eliminate some of the extra new lines, so the middle examples would become this:
or this:
The text was updated successfully, but these errors were encountered: