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

Oren Milman orenmn at gmail.com
Wed May 31 11:28:10 EDT 2017


the 'goto fail' bug is a somewhat extreme reminder for why such braces are
a good idea (as Victor said) -
https://www.imperialviolet.org/2014/02/22/applebug.html

On Wed, May 31, 2017 at 6:25 PM Paul Moore <p.f.moore at gmail.com> wrote:

> On 31 May 2017 at 15:11, Victor Stinner <victor.stinner at gmail.com> wrote:
> > 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".
>
> As a practical compromise, I'd argue that if you're changing
> *existing* code, you should retain the current style. For *new* code,
> always add braces. So, changing
>
> if (func == NULL)
>     return NULL;
> /* further code */
>
> to
>
> if (func1 == NULL)
>     return NULL;
> /* further code */
>
> you would leave out the braces. But changing
>
> /* Code using func */
>
> to
>
> if (func == NULL) {
>     return NULL;
> }
> /* Code using func */
>
> you include the braces, because it's new code.
>
> I'm not against making the PEP mandate braces, but I don't think it's
> necessary to resolve the situation you describe as having triggered
> the suggestion :-)
>
> Paul
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/orenmn%40gmail.com
>
-- 

-Oren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170531/e494f368/attachment.html>


More information about the Python-Dev mailing list