[issue12188] PEP 7, C style: add ++ policy and explanation
New submission from Terry J. Reedy
before. There is a common idiom, *pointer++ =<something>, and whenever you see that you know that you are appending something to an output buffer. Perhaps the most important idea here is that this maintains the *invariant* "pointer points just after the last thing in the buffer". Always maintaining the invariant is better than trying to micro-optimize things so as to avoid updating dead values. The compiler is better at that."
A condensed version of the above added to PEP 7 would help new developers see the usage as local idiom rather than style bug.
----------
assignee: docs@python
components: Documentation
messages: 136991
nosy: docs@python, terry.reedy
priority: normal
severity: normal
status: open
title: PEP 7, C style: add ++ policy and explanation
_______________________________________
Python tracker
Changes by Eric V. Smith
Changes by Eli Bendersky
Ezio Melotti
Changes by STINNER Victor
Antoine Pitrou
Eric V. Smith
Ezio Melotti
Antoine Pitrou
If there are a few of these idioms, I'm not against adding a new section to PEP 7 (something like the "Programming Recommendations" section in the PEP 8). It's just not worth doing it for the "*p++ = x;" idiom alone IMHO.
If these are recommandations, perhaps we should put them in the devguide
instead?
But I agree that it's not worth doing it only for "*p++" anyway.
----------
_______________________________________
Python tracker
Terry J. Reedy
On Wed, Jun 8, 2011 at 8:12 AM, Nick Coghlan
I actually thought Brett's rationale in the checkin comment was reasonable (if you get in the habit of putting constants on the left, then the classic "'=' instead of '=='" typo is a compiler error instead of a reassignment).
[I understand this rationale too; I forget what I actually did when I was writing C.]
I really like consistency across the code base. I really don't like constant-on-the-left, and it's basically not used in the current codebase. Please be consistent and don't start using it.
[I suspect I did this.]
Call it a +0 in favour of letting people put constants on the left in C code if they prefer it that way, so long as any given if/elif chain is consistent in the style it uses.
Sorry, I give it a -1. (I'd like to be able to read the codebase still... :-)
I bet there will be more things for a new section.
----------
title: PEP 7, C style: add ++ policy and explanation -> PEP 7 (or guide) add C style policies and explanation
type: feature request ->
versions: +Python 2.7, Python 3.2, Python 3.3
_______________________________________
Python tracker
Changes by Eli Bendersky
anthony shaw
participants (7)
-
anthony shaw
-
Antoine Pitrou
-
Eli Bendersky
-
Eric V. Smith
-
Ezio Melotti
-
STINNER Victor
-
Terry J. Reedy