On Sep 15, 2009, at 2:52 PM, Lisandro Dalcin wrote:

> Sorry for the noise... Yes, the caller does the typecheck for cdef
> functions, so no danger at all...
>
>>> Python is just not designed for it. If we try to use types to
>>> "encourage
>>> good programming practice" then we essentially need to develop a new
>>> language from ground up, which may or may not look like Python.
>
> I've NEVER said that using types is encourages good programming
> practice... All as I commented if that if you write a cdef function
> with a typed arg, and next call it with an untyped value, it would be
> NICE that Cython let me know that... just because that WARNING could
> spot a real bug, or I could even save the runtime typecheck at the
> caller by using a typed value. And I just asked for a Cython warning,
> and I do not ever bother if that warning is not enabled by default...
>
>> From my own code, I have two primary use cases for cdef functions/ 
>> methods:
>
> (1) internal, private helper routines, that should handle C types and
> cdef classes
> (2) public C-API for consumption in external C code.
>
> For (1), when I use typed arguments I have VERY good reasons for it,
> and would like Cython to point me any call with untyped args (because
> an untyped arg is either a bug or an unnecessary runtime typecheck in
> the caller)...
>
> For (2), the no-typecheck on the callee is unsafe, and I have to
> manually do the typecheck....
>
>
>>>
>>> I even had a seperate slide in my SciPy 09 presentation telling  
>>> people
>>> that static type checking (as a programming model) was not a valid
>>> usecase for Cython; "Cython is typed because it has to, not  
>>> because it
>>> wants to." :-)
>>
>
> I do not buy that as an absolute truth... If some people use Cython to
> write/speedup Python code, then they will likely share that view...
> But if you use Cython closer to the C/C++ part, where you have to
> interact with C types and opaque handles, and typed cdef classes and
> cdef methods, and all that for maximum speed and calling external lib
> functions, then you start to think different and will appreciate if
> Cython help you to save unnecessary runtime typechecking by some sort
> or "static typing" features (even if all what Cython does is
> generating warnings).

This is one thing that cython -a is good for, it lets you easily spot  
cases where unnecessarily type checking, etc. is performed.

- Robert


_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to