Re: [openssl-project] Style guide update -- summary so far
On Mon, Feb 05, 2018 at 08:43:04PM +0100, Dr. Matthias St. Pierre wrote: > > > Am 05.02.2018 um 19:13 schrieb Salz, Rich: > > > > > > Do not put a size after sizeof; do use parens. > > > > nit: Do not put a /space /after sizeof. > > > > > > > Treat a single-statement with comment as if it were multi-line and use > > curly braces > > > > > > > > if (test()) { > > > > /* already alerted */ > > > > close(); > > > > } > > > > > > > > Wasn't there also the suggestion by someone that if one part of an > if-else statements needs braces that the other part should get some, too? > > if (foo) > do_this(); > else > do_that(); > > vs. > > if (foo) { > /* some statements */ > ... > } else { > ... > } As already pointed out by others, it's mostly already in the style guide. What is not in it is the combination with a comment: if (foo) /* some comment */ do_this(); else do_that(); And it's been suggested to use curly braces for that. Kurt ___ openssl-project mailing list openssl-project@openssl.org https://mta.openssl.org/mailman/listinfo/openssl-project
Re: [openssl-project] Style guide update -- summary so far
* nit: Do not put a space after sizeof. fixed. * Wasn't there also the suggestion by someone that if one part of an if-else statements needs braces that the other part should get some, too? It already says that. ___ openssl-project mailing list openssl-project@openssl.org https://mta.openssl.org/mailman/listinfo/openssl-project
Re: [openssl-project] Style guide update -- summary so far
On 05/02/18 19:43, Dr. Matthias St. Pierre wrote: > > Wasn't there also the suggestion by someone that if one part of an > if-else statements needs braces that the other part should get some, too? That's already in the style guide: Do not unnecessarily use braces around a single statement: if (condition) action(); and if (condition) do_this(); else do_that(); If one of the branches is a compound statement, then use braces on both parts: if (condition) { do_this(); do_that(); } else { otherwise(); } Matt ___ openssl-project mailing list openssl-project@openssl.org https://mta.openssl.org/mailman/listinfo/openssl-project
Re: [openssl-project] Style guide update -- summary so far
Am 05.02.2018 um 19:13 schrieb Salz, Rich: > > > Do not put a size after sizeof; do use parens. > nit: Do not put a /space /after sizeof. > > > Treat a single-statement with comment as if it were multi-line and use > curly braces > > > > if (test()) { > > /* already alerted */ > > close(); > > } > > > Wasn't there also the suggestion by someone that if one part of an if-else statements needs braces that the other part should get some, too? if (foo) do_this(); else do_that(); vs. if (foo) { /* some statements */ ... } else { ... } Matthias ___ openssl-project mailing list openssl-project@openssl.org https://mta.openssl.org/mailman/listinfo/openssl-project
Re: [openssl-project] Style guide update -- summary so far
➢ In general we should prefer ossl_assert over assert. Never use OPENSSL_assert() in libcrypto or libssl. Maybe that’s all to put into the guide, then. ___ openssl-project mailing list openssl-project@openssl.org https://mta.openssl.org/mailman/listinfo/openssl-project
[openssl-project] Style guide update -- summary so far
A summary of the discussion thread so far. Not surprisingly, it’s all about the whitespace. :) The descriptions here were written to be understandable stand-alone. Once we come to a conclusion, we’ll wordsmith them into the coding style. Do not put a size after sizeof; do use parens. When breaking long lines, if there are Boolean conditionals, put them at the start of the line. Consider doing this consistently, and don’t merge even if they fit. For example: some_long_condition() && short1() && short2() should be three lines. Related conditions should be on one line if they fit, else given an extra level of indent some_long_condition() && (short1() || short2()) && some_other_flag != 0 If the expression for an if statement does not fit, indent the continuation lines an extra level if (this_is_true() && !that_is_false()) { code(); …. Try not to break long lines across a function call, but if you have to, indent the rest of the parameter list to be after the function’s opening paren. Remember a blank line after variable declarations (even local ones). Treat a single-statement with comment as if it were multi-line and use curly braces if (test()) { /* already alerted */ close(); } Note that this could end up having “cascading curly” effects. Arguments inside macro expansions should be parenthesized. #define foo(a, b) ((a) + (b)) Free routines should properly handle null; don’t check for null before calling a free routine. When possible, use size_t for sizes of things (including array indicies) [ Matt said “initialize in the declaration if appropriate; can someone provide wording? ] This is controversial, so maybe drop it. Don’t use else after return or goto unless it makes the flow more clear. Argument names in function definition should match the declaration, but you can use “unused_” as a prefix in the definition for unused arguments. Use ossl_assert, not assert. Do not forget to handle the error condition as asserts are not compiled into production code. ___ openssl-project mailing list openssl-project@openssl.org https://mta.openssl.org/mailman/listinfo/openssl-project