Given the number of serious problems that lack of braces causes, I
like this proposal. It's indicative that both Rust and Go require the
{}, for reasons of safety.On Wed, Jun 19, 2019 at 11:27 AM Jonathan Neuschäfer <[email protected]> wrote: > > On Wed, Jun 19, 2019 at 01:39:50PM -0400, Patrick Georgi via coreboot wrote: > > Hey everybody, > > > > in today's leadership meeting, the question was brought up if we want > > to normalize the coding style in coreboot to _always_ use braces in > > if, else and for statements, even if it's just one statement they're > > wrapping. > > > > The arguments made in favor were: > > > > 1. it's more consistent > > 2. it's safer: you won't accidentally add a statement that is outside > > the context it's supposed to run in (or even move a statement out > > into the parent context by inserting another statement) > > > > So instead of: > > > > if (foo) > > bar(); > > else { > > baz(); > > quux(); > > } > > > > we'd do: > > > > if (foo) { > > bar(); > > } else { > > baz(); > > quux(); > > } > > Quick sidenote: Under the old rules[1], inherited from the Linux > kernel coding style[2], the above example would look the same: > > | [...] > | This does not apply if only one branch of a conditional statement is a > | single statement; in the latter case use braces in both branches: > | > | if (condition) { > | do_this(); > | do_that(); > | } else { > | otherwise(); > | } > > ... so a better example would be one where technically no parentheses > are required at all: > > if (foo) > bar(); > else > baz(); > > becomes: > > if (foo) { > bar(); > } else { > baz(); > } > > > greetings, > Jonathan Neuschäfer > > > [1]: https://doc.coreboot.org/coding_style.html#placing-braces-and-spaces > [2]: > https://www.kernel.org/doc/html/latest/process/coding-style.html?highlight=coding%20style#placing-braces-and-spaces > _______________________________________________ > coreboot mailing list -- [email protected] > To unsubscribe send an email to [email protected] _______________________________________________ coreboot mailing list -- [email protected] To unsubscribe send an email to [email protected]

