Re: [Tutor] Python Extensions in C

2011-06-02 Thread James Reynolds
find if they > > are all together. > > Other than that I can't see the error, but its late and thats > quite a lot of code for a Python programmer to wade through! :-) > > > Alan Gauld > Author of the Learn To Program website > > http://www.alan-g.me.uk/ > > > --

Re: [Tutor] Python Extensions in C

2011-06-01 Thread ALAN GAULD
d Cc: tutor@python.org Sent: Wednesday, 1 June, 2011 20:49:44 Subject: Re: [Tutor] Python Extensions in C So I've been continuing with my experiment above, and I've made some good progress and learned some new things as I've been going. I've expanded it out a little bit, and you

Re: [Tutor] Python Extensions in C

2011-06-01 Thread James Reynolds
So I've been continuing with my experiment above, and I've made some good progress and learned some new things as I've been going. I've expanded it out a little bit, and you can see the code here: http://pastebin.com/gnW4xQNv I've tried to incorporate most of your su

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Alan Gauld
"James Reynolds" wrote As far as the null point goes, it shouldn't be null at all once it gets to the point Alan pointed out. The pointer is set in (for example) stat_avg seq = PySequence_Fast(obj, "Expected a Sequence"); Can the function fail? If so what does it return? That was my p

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Alan Gauld
"James Reynolds" wrote I'll look into your suggestion regarding comprehension (i'm not sure what that means in a programing sense, but I'm sure I'll find out!) Its the English meaning of the word. Studies have shown that the layout of code (indentation, placement of braces etc) have a big e

Re: [Tutor] Python Extensions in C

2011-05-26 Thread ALAN GAULD
> I suppose it's up to the programmer. It is, provided the programmer is remembering that the audience is not him/herself buty the many other programmers who will have to read and maintain the code over the years to follow. So if the programmer genuinely believes that one form is clearer the

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Rachel-Mikel ArceJaeger
I suppose it's up to the programmer. Personally, I find something like this: variable += something a lot easier to read than temp = something variable += temp For me, it's just another variable I have to worry about allocating/deallocating/seeing if it's used anywhere else/accidentally using

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Stefan Behnel
James Reynolds, 26.05.2011 21:34: On Thu, May 26, 2011 at 3:07 PM, Stefan Behnel wrote: Stefan Behnel, 26.05.2011 18:10: James Reynolds, 26.05.2011 17:22: As an intellectual exercise, I wanted to try my hand at writing some extensions in C. This is fine for en exercise, and I hope you had

Re: [Tutor] Python Extensions in C

2011-05-26 Thread James Reynolds
On Thu, May 26, 2011 at 3:07 PM, Stefan Behnel wrote: > Stefan Behnel, 26.05.2011 18:10: > > James Reynolds, 26.05.2011 17:22: >> >>> As an intellectual exercise, I wanted to try my hand at writing some >>> extensions in C. >>> >> >> This is fine for en exercise, and I hope you had fun doing thi

Re: [Tutor] Python Extensions in C

2011-05-26 Thread James Reynolds
at 1:52 PM, Patty wrote: > > - Original Message - From: "Stefan Behnel" > To: > Sent: Thursday, May 26, 2011 9:10 AM > Subject: Re: [Tutor] Python Extensions in C > > > > James Reynolds, 26.05.2011 17:22: >> >>> As an intellectual exercise, I want

Re: [Tutor] Python Extensions in C

2011-05-26 Thread James Reynolds
Thank you Rachel and Alan for the feedback. Oddly enough, I had created an exception between the time I sent this and your response to catch occasions when the list is empty (I will need to test a few other things, like what if the list holds items other than strictly numbers?) I did utilize some

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Stefan Behnel
Stefan Behnel, 26.05.2011 18:10: James Reynolds, 26.05.2011 17:22: As an intellectual exercise, I wanted to try my hand at writing some extensions in C. This is fine for en exercise, and I hope you had fun doing this. However, for real code, I suggest you use Cython instead. Your module would

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Stefan Behnel
Rachel-Mikel ArceJaeger, 26.05.2011 17:46: A couple small things that will help improve memory management Rather than avg = sumall / count; return avg; Just return sumall/count instead. Then you don't have to waste a register or assignment operation. Division is expensive. Avoid it when you can

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Patty
"Alan Gauld" wrote in message news:irm3ae$vpl$1...@dough.gmane.org... "Rachel-Mikel ArceJaeger" wrote Consider these the ravings of an ex maintenance programmer who spent far too much of his life deciphering other folks "clever" C code... It wasn't clever and it wasn't working! Alan G.

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Patty
- Original Message - From: "Stefan Behnel" To: Sent: Thursday, May 26, 2011 9:10 AM Subject: Re: [Tutor] Python Extensions in C James Reynolds, 26.05.2011 17:22: As an intellectual exercise, I wanted to try my hand at writing some extensions in C. This is fine for e

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Alan Gauld
"Rachel-Mikel ArceJaeger" wrote avg = sumall / count; return avg; Just return sumall/count instead. Then you don't have to waste a register or assignment operation. Readibility counts in C too. And premature optimisation is even more of an evil since C is harder to read to start with Thi

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Alan Gauld
"James Reynolds" wrote I was wondering if you all could look over my code and give some feedback. Here is the link for the code: http://pastebin.com/jw3ihfsN Some style issues, the indentation is inconsistent. Also the braces positioning is one of the worst for comprehension (See the book C

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Stefan Behnel
James Reynolds, 26.05.2011 17:22: As an intellectual exercise, I wanted to try my hand at writing some extensions in C. This is fine for en exercise, and I hope you had fun doing this. However, for real code, I suggest you use Cython instead. Your module would have been substantially simpler

Re: [Tutor] Python Extensions in C

2011-05-26 Thread Rachel-Mikel ArceJaeger
A couple small things that will help improve memory management Rather than avg = sumall / count; return avg; Just return sumall/count instead. Then you don't have to waste a register or assignment operation. Division is expensive. Avoid it when you can. Here, for (a=0; a != count; a++) {

[Tutor] Python Extensions in C

2011-05-26 Thread James Reynolds
Hello All: As an intellectual exercise, I wanted to try my hand at writing some extensions in C. I was wondering if you all could look over my code and give some feedback. Here is the link for the code: http://pastebin.com/jw3ihfsN I have zero experience coding in C (and not much more coding in