[Python-Dev] Update PEP 7 to require curly braces in C (original) (raw)
Maciej Szulik soltysh at gmail.com
Tue Jan 19 04:00:03 EST 2016
- Previous message (by thread): [Python-Dev] Update PEP 7 to require curly braces in C
- Next message (by thread): [Python-Dev] Update PEP 7 to require curly braces in C
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To add my additional 0.02$ to the discussion. Quite a while ago my coworkers and I agreed to use strict rules regarding code formatting. That idea turned into a formatter we've had committed in the project itself. This forced everyone on the team to use it and thus producing exactly "the same looking" code. I found it very nice, although we've debated over how those rules should be applied for good couple months, that was at one of the previous companies I've worked for. Currently by day I'm working with Go, which go-fmt is by default required for all our projects and I found it extremely handy see [1], [2], [3].
Maciej
[1] https://github.com/openshift/origin/ [2] https://github.com/openshift/source-to-image/ [3] https://github.com/kubernetes/kubernetes
On Tue, Jan 19, 2016 at 9:48 AM, M.-A. Lemburg <mal at egenix.com> wrote:
On 19.01.2016 00:20, Brett Cannon wrote: > On Sun, 17 Jan 2016 at 11:10 Brett Cannon <brett at python.org> wrote: > >> While doing a review of http://bugs.python.org/review/26129/ I asked to >> have curly braces put around all
if
statement bodies. Serhiy pointed out >> that PEP 7 says curly braces are optional: >> https://www.python.org/dev/peps/pep-0007/#id5. I would like to change >> that. >> >> My argument is to require them to prevent bugs like the one Apple made >> with OpenSSL about two years ago: >> https://www.imperialviolet.org/2014/02/22/applebug.html. Skipping the >> curly braces is purely an aesthetic thing while leaving them out can lead >> to actual bugs. >> >> Anyone object if I update PEP 7 to remove the optionality of curly braces >> in PEP 7? >> > > Currently this thread stands at:Make that: > +1 > Brett > Ethan > Robert > Georg > Nick > Maciej Szulik > +0 > Guido > -0 > Serhiy > -1 MAL > Victor (maybe; didn't specifically vote) > Larry > Stefan There are plenty other cases where typos can ruin the flow of your code in C; the discussed case is not a very common one. I find the whole discussion a bit strange: In Python we're advocating not having to use curly braces, because whitespace already provides the needed semantics for us, yet you are now advocating that without adding extra curly braces we'd be in danger of writing wrong code. The Apple bug can happen in Python just as well: if a: runiftrue() else: runiffalse() can turn into (say by hitting a wrong key in the editor): if a: runiftrue() runiffalse() (runiffalse is now run when a is true, and nothing is done in case a is false) So what's the correct way to address this ? It's having a test for both branches (a is true, a is false), not starting to write e.g. if a: runiftrue() if not a: runif false() to feel more "secure". Also note that the extra braces won't necessarily help you. If you remove "else" from: if (a) { runiftrue(); } else { runiffalse(); } you get exactly the same Apply bug as before, only with more curly braces. This all sounds a bit like security theater to me ;-) I'd say: people who feel better using the extra braces can use them, while others who don't need them can go ahead as always ... and both groups should write more tests :-) BTW: There are other things in PEP 7 which should probably be updated instead, e.g. it still says we should use C89, but we're having more and more C99 code (mostly new library functions) in CPython. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Jan 19 2016) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/
::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/
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/soltysh%40gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160119/e24f85b9/attachment.html>
- Previous message (by thread): [Python-Dev] Update PEP 7 to require curly braces in C
- Next message (by thread): [Python-Dev] Update PEP 7 to require curly braces in C
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]