[Python-Dev] PEP 7 clarification request: braces (original) (raw)
Benjamin Peterson benjamin at python.org
Mon Jan 2 15:54:02 CET 2012
- Previous message: [Python-Dev] Code reviews
- Next message: [Python-Dev] PEP 7 clarification request: braces
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2012/1/1 Nick Coghlan <ncoghlan at gmail.com>:
I've been having an occasional argument with Benjamin regarding braces in 4-line if statements:
Python's C code has been dropping braces long before I ever arrived. See this beautiful example in dictobject.c, for example:
if (numfree < PyDict_MAXFREELIST && Py_TYPE(mp) == &PyDict_Type)
free_list[numfree++] = mp;
else
Py_TYPE(mp)->tp_free((PyObject *)mp);
There's even things like this:
if (ep->me_key == dummy)
freeslot = ep;
else {
if (ep->me_hash == hash && unicode_eq(ep->me_key, key))
return ep;
freeslot = NULL;
}
where I would normally put braces on both statements.
I think claims of its maintainability are exaggerated. (If someone could cite an example of a bug caused by braces, I'd be interested to see it.) If I start editing one of the bodies, emacs will dedent, so that I know I'm back to the containing block. By virtue of being 5 lines long, it's a very easy case to see and fix as you edit it.
I think it's fine Nick raised this. PEP 7 is not very explicit about braces at all.
-- Regards, Benjamin
- Previous message: [Python-Dev] Code reviews
- Next message: [Python-Dev] PEP 7 clarification request: braces
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]