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
One common complaint I've seen (and made myself) coming to rust-guide-formatted code from many other languages is the vertical-ness of a lot of common rust code. This leads to less context when viewing diffs (or functions entirely in smaller editor windows) which can be a common source of bugs. There's good reason for the vertical layout in many cases, of course - it can substantially improve scan-ability of code layout, and like all things, there is a balance to be had.
One common pattern in Rust is a somewhat long line causing a closing ) to be on its own line. While this can improve scan-ability, it can generate some very awkward looking chains, especially with a trailing unwrap(), which is also exceedingly common.
For example, we have some code which is formatted as
let data = Vec::<u8>::from_hex(
"02020202020202020202 longish hex constant",
)
.unwrap();
At the risk of starting a long discussion and flame-war on the topic of chains, I don't believe scan-ability of the code is substantially impacted (or arguably positively impacted by a change to allow the unwrap to appear on the same line as the ), as follows:
let data = Vec::<u8>::from_hex(
"02020202020202020202 longish hex constant",
).unwrap();
As a general principle, though its totally reasonable to have it be of the lowest priority, having a "provide more context in diffs and during editing by making things single-line where it does not at all impact scan-ability" principle would serve to avoid some bugs which, in my experience, are not entirely uncommon, though arguably scan-ability can sometimes avoid more/other bugs.
The text was updated successfully, but these errors were encountered:
One common complaint I've seen (and made myself) coming to rust-guide-formatted code from many other languages is the vertical-ness of a lot of common rust code. This leads to less context when viewing diffs (or functions entirely in smaller editor windows) which can be a common source of bugs. There's good reason for the vertical layout in many cases, of course - it can substantially improve scan-ability of code layout, and like all things, there is a balance to be had.
One common pattern in Rust is a somewhat long line causing a closing
)
to be on its own line. While this can improve scan-ability, it can generate some very awkward looking chains, especially with a trailingunwrap()
, which is also exceedingly common.For example, we have some code which is formatted as
according to https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/expressions.md#multi-line-elements
At the risk of starting a long discussion and flame-war on the topic of chains, I don't believe scan-ability of the code is substantially impacted (or arguably positively impacted by a change to allow the
unwrap
to appear on the same line as the)
, as follows:As a general principle, though its totally reasonable to have it be of the lowest priority, having a "provide more context in diffs and during editing by making things single-line where it does not at all impact scan-ability" principle would serve to avoid some bugs which, in my experience, are not entirely uncommon, though arguably scan-ability can sometimes avoid more/other bugs.
The text was updated successfully, but these errors were encountered: