[Pyrex] [Cython-dev] req - block-local variables

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Dec 9 00:57:35 CET 2007


Robert Bradshaw wrote:
> On Dec 8, 2007, at 12:07 PM, Sven Berkvens-Matthijsse wrote:
> 
>>> On Sat, 2007-12-08 at 10:03 +0100, Stefan Behnel (I think) wrote:
>>>
>>> I find that with large functions, it's distracting to keep flipping
>>> between lines of code in the function and the cdef vars at the top
>>> of the function.

I would argue that if you can't fit them both on the screen
at once, your function is too big and needs breaking up.

> Variables don't have to be defined at the top of a function,  
> they just (currently) can't be defined inside blocks. This  restriction 
> could be removed (with leaking) fairly easily and would  solve this 
> issue. What are the drawbacks to doing this.
> 
> Greg, I'm cc'ing you because I'm guessing you had some reason to  
> explicitly dis-allow this. Comments?

Well, the "with leaking" is kind of a clue. Various aspects of
the code generation assume that function-local variables live for
the whole lifetime of the function call and only need to be
cleaned up at the end. Changing that would require some careful
thought, and there doesn't seem to be any strong motivation to
try.

Possibly it could be made legal to declare variables anywhere
in the function, but still have them all at function scope.
But that might be confusing to people expecting them to be
block-scoped.

--
Greg



More information about the Pyrex mailing list