C99

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

C99

Charles R Harris
Hi All,

I've a PR up converting travis testing to use C99. I suspect we may not want to merge it for a while, but it does raise a couple of style questions that we should probably settle up front. Namely:

  • Should we allow // style comments
  • Should we allow variable declarations after code
I am sure there are others to consider that haven't occurred to me. I confess that I am not a big fan of allowing either, but am probably prejudiced by early familiarity with C89 and long years working to that spec.

Thoughts?

Chuck

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: C99

Eric Wieser

Thanks for the first step on this!

Should we allow // style comments

I don’t think it matters too much. I think it might be a little messy to have a mix of the two styles where // means “post py3” and /* */ means pre-py3 - but at the same time, I do slightly prefer the C++-style. For C contributors coming from python, I’d expect that it feels more natural to only have to put a comment marker at the start of the line. We could convert the /**/-style to //-style with a tool, but it’s probably not worth the churn or time.

Should we allow variable declarations after code

I’d be very strongly in favor of this - it makes it much easier to extract helper functions if variables are declared as late as they can be - plus it make it easier to reason about early returns not needing goto fail.

Related to this feature, I think allowing for(int i = 0; i < N; i++) is a clear win.

Eric

On Fri, 7 Sep 2018 at 18:56 Charles R Harris charlesr.harris@... wrote:

Hi All,

I've a PR up converting travis testing to use C99. I suspect we may not want to merge it for a while, but it does raise a couple of style questions that we should probably settle up front. Namely:

  • Should we allow // style comments
  • Should we allow variable declarations after code
I am sure there are others to consider that haven't occurred to me. I confess that I am not a big fan of allowing either, but am probably prejudiced by early familiarity with C89 and long years working to that spec.

Thoughts?

Chuck
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: C99

Charles R Harris


On Sat, Sep 8, 2018 at 12:02 AM Eric Wieser <[hidden email]> wrote:

Thanks for the first step on this!

Should we allow // style comments

I don’t think it matters too much. I think it might be a little messy to have a mix of the two styles where // means “post py3” and /* */ means pre-py3 - but at the same time, I do slightly prefer the C++-style. For C contributors coming from python, I’d expect that it feels more natural to only have to put a comment marker at the start of the line. We could convert the /**/-style to //-style with a tool, but it’s probably not worth the churn or time.

Should we allow variable declarations after code

I’d be very strongly in favor of this - it makes it much easier to extract helper functions if variables are declared as late as they can be - plus it make it easier to reason about early returns not needing goto fail.

Related to this feature, I think allowing for(int i = 0; i < N; i++) is a clear win.

Eric


Thinking about this some more, a good argument for going to full C99 is that outside code written in that style can be brought in without a lot of work.

Chuck

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: C99

ralfgommers


On Sat, Sep 8, 2018 at 6:07 AM Charles R Harris <[hidden email]> wrote:


On Sat, Sep 8, 2018 at 12:02 AM Eric Wieser <[hidden email]> wrote:

Thanks for the first step on this!

Should we allow // style comments

I don’t think it matters too much. I think it might be a little messy to have a mix of the two styles where // means “post py3” and /* */ means pre-py3 - but at the same time, I do slightly prefer the C++-style. For C contributors coming from python, I’d expect that it feels more natural to only have to put a comment marker at the start of the line. We could convert the /**/-style to //-style with a tool, but it’s probably not worth the churn or time.

Should we allow variable declarations after code

I’d be very strongly in favor of this - it makes it much easier to extract helper functions if variables are declared as late as they can be - plus it make it easier to reason about early returns not needing goto fail.

Related to this feature, I think allowing for(int i = 0; i < N; i++) is a clear win.

Eric


Thinking about this some more, a good argument for going to full C99 is that outside code written in that style can be brought in without a lot of work.

Agreed. And we already have the pocketfft PR to prove that.

Ralf


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: C99

Charles R Harris


On Sat, Sep 8, 2018 at 11:02 AM Ralf Gommers <[hidden email]> wrote:


On Sat, Sep 8, 2018 at 6:07 AM Charles R Harris <[hidden email]> wrote:


On Sat, Sep 8, 2018 at 12:02 AM Eric Wieser <[hidden email]> wrote:

Thanks for the first step on this!

Should we allow // style comments

I don’t think it matters too much. I think it might be a little messy to have a mix of the two styles where // means “post py3” and /* */ means pre-py3 - but at the same time, I do slightly prefer the C++-style. For C contributors coming from python, I’d expect that it feels more natural to only have to put a comment marker at the start of the line. We could convert the /**/-style to //-style with a tool, but it’s probably not worth the churn or time.

Should we allow variable declarations after code

I’d be very strongly in favor of this - it makes it much easier to extract helper functions if variables are declared as late as they can be - plus it make it easier to reason about early returns not needing goto fail.

Related to this feature, I think allowing for(int i = 0; i < N; i++) is a clear win.

Eric


Thinking about this some more, a good argument for going to full C99 is that outside code written in that style can be brought in without a lot of work.

Agreed. And we already have the pocketfft PR to prove that.

Hmm, maybe  C_STYLE_GUIDE.rst.txt should be an NEP?

Chuck

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: C99

ralfgommers


On Sat, Sep 8, 2018 at 12:24 PM Charles R Harris <[hidden email]> wrote:


On Sat, Sep 8, 2018 at 11:02 AM Ralf Gommers <[hidden email]> wrote:


On Sat, Sep 8, 2018 at 6:07 AM Charles R Harris <[hidden email]> wrote:


On Sat, Sep 8, 2018 at 12:02 AM Eric Wieser <[hidden email]> wrote:

Thanks for the first step on this!

Should we allow // style comments

I don’t think it matters too much. I think it might be a little messy to have a mix of the two styles where // means “post py3” and /* */ means pre-py3 - but at the same time, I do slightly prefer the C++-style. For C contributors coming from python, I’d expect that it feels more natural to only have to put a comment marker at the start of the line. We could convert the /**/-style to //-style with a tool, but it’s probably not worth the churn or time.

Should we allow variable declarations after code

I’d be very strongly in favor of this - it makes it much easier to extract helper functions if variables are declared as late as they can be - plus it make it easier to reason about early returns not needing goto fail.

Related to this feature, I think allowing for(int i = 0; i < N; i++) is a clear win.

Eric


Thinking about this some more, a good argument for going to full C99 is that outside code written in that style can be brought in without a lot of work.

Agreed. And we already have the pocketfft PR to prove that.

Hmm, maybe  C_STYLE_GUIDE.rst.txt should be an NEP?

+1


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion