A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-May/148084.html below:

[Python-Dev] PEP 7 and braces { .... } on if

[Python-Dev] PEP 7 and braces { .... } on ifVictor Stinner victor.stinner at gmail.com
Wed May 31 10:11:39 EDT 2017
Hi,

I have a question on the CPython coding code for C code, the PEP 7:
https://www.python.org/dev/peps/pep-0007/

"""
Code structure: (...); braces are strongly preferred but may be
omitted where C permits, and they should be formatted as shown:

if (mro != NULL) {
    ...
}
else {
    ...
}
"""

This section was updated after the creation of CPython in 1991, so as
you may expect, a lot of existing C code doesn't respect this coding
style. I'm trying to slowly add "missing" braces and indent as the
example *when I have to modify existing code*.

The problem is the "strongly preferred" and "omitted where C permits"
part. I would like to make the PEP 7 more explicit on that part since
in each review, I disagree with Serhiy who wants to omit them.
Example:

if (func == NULL)
    return NULL;

versus

if (func == NULL) {
    return NULL;
}

I now prefer the version with braces. It's more verbose, but it
prevents bugs when the code is modified later for whatever reasons.
IMHO it also makes the code easily to read and to understand.

So I would suggest to modify the PEP 7 to *always* require braces for if.

I would also suggest to require braces on "for(...) { ... }" and
"while(...) { ... }". But only if the code has to be modified, not
only to update the coding style.

Changes which are pure coding style changes should be rejected to
avoid conflicts with other pending pull requests and "code churn".

Victor
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4