Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 7 (or guide) add C style policies and explanation #56397

Closed
terryjreedy opened this issue May 26, 2011 · 8 comments
Closed

PEP 7 (or guide) add C style policies and explanation #56397

terryjreedy opened this issue May 26, 2011 · 8 comments
Labels
docs Documentation in the Doc dir

Comments

@terryjreedy
Copy link
Member

BPO 12188
Nosy @gvanrossum, @terryjreedy, @pitrou, @vstinner, @ericvsmith, @ezio-melotti, @tonybaloney

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2019-05-09.01:07:47.627>
created_at = <Date 2011-05-26.18:19:32.365>
labels = ['docs']
title = 'PEP 7 (or guide) add C style policies and explanation'
updated_at = <Date 2019-05-09.01:07:47.620>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2019-05-09.01:07:47.620>
actor = 'anthonypjshaw'
assignee = 'docs@python'
closed = True
closed_date = <Date 2019-05-09.01:07:47.627>
closer = 'anthonypjshaw'
components = ['Documentation']
creation = <Date 2011-05-26.18:19:32.365>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 12188
keywords = []
message_count = 8.0
messages = ['136991', '137111', '137808', '137809', '137814', '137818', '138143', '341951']
nosy_count = 8.0
nosy_names = ['gvanrossum', 'terry.reedy', 'pitrou', 'vstinner', 'eric.smith', 'ezio.melotti', 'docs@python', 'anthonypjshaw']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue12188'
versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

@terryjreedy
Copy link
Member Author

In response to a discussion of a patch removing 'useless' post-increments, (which issue has apparently come up before)
Guido posted
"> Sorry to butt in here, but I agree with Eric that it was better

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.

@terryjreedy terryjreedy added the docs Documentation in the Doc dir label May 26, 2011
@ezio-melotti
Copy link
Member

I'm not sure it's worth adding this to the PEP-7. The PEP is about conventions and style not idioms.
PEP-8 has a section about "Programming Recommendations" that contains a few idioms, but since PEP-7 doesn't have an equivalent section, I think that explaining this idiom (and not others) will look out of place.

@pitrou
Copy link
Member

pitrou commented Jun 7, 2011

Indeed, I don't think that's appropriate. Also, it's not about ++ in general but a particular use of it.

@pitrou pitrou added the type-feature A feature request or enhancement label Jun 7, 2011
@ericvsmith
Copy link
Member

But don't you think we should put information like this somewhere, even if it's not in PEP-7? We've had a discussion about this particular issue (idiomatic pointer increments when appending to a buffer) at least twice, and there's also the recent "if (const == variable)" issue that feels similar to me.

It seems to me that recording these decisions somewhere has value, just so we don't have to revisit them.

@ezio-melotti
Copy link
Member

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.

@pitrou
Copy link
Member

pitrou commented Jun 7, 2011

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.

@terryjreedy
Copy link
Member Author

We have a second item for the PEP (or Guide) section (but I think I prefer in the PEP so as to have one place to look for such things.).
So I changed the title a bit.

On 6/10/2011 3:49 PM, Guido van Rossum wrote:

On Wed, Jun 8, 2011 at 8:12 AM, Nick Coghlan<ncoghlan@gmail.com>
> 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.

@terryjreedy terryjreedy changed the title PEP 7, C style: add ++ policy and explanation PEP 7 (or guide) add C style policies and explanation Jun 11, 2011
@terryjreedy terryjreedy removed the type-feature A feature request or enhancement label Jun 11, 2011
@tonybaloney
Copy link
Mannequin

tonybaloney mannequin commented May 9, 2019

Hi,

This discussion came to a stop, but it doesn't seem conclusive.

PEP discussions are now in GitHub on https://github.com/python/peps/issues so I'm going to close this BPO issue.

There is no additional section in PEP-7 for this level of detail, there is also no tooling in place (afaik) to retroactively apply or inspect these types of issues, so this would need to be discussed in the PEP issue,

@tonybaloney tonybaloney mannequin closed this as completed May 9, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

4 participants