Sturla Molden wrote:
> On 3/16/2009 11:59 AM, Stefan Behnel wrote:
>
>> My clear vote is for Python-semantics on "x%y" and for a helper function
>> "cython.cmod(x,y)" that boils down to a straight and fast C mod operator
>> without value fixing.
>
> As I see it,
>
> cdef int a, b, c
>
> is a request to "step into C" when using these variables.
It's hard to have an argument about personal impressions (as in "as I see
it"), so I won't go there. But let me clarify that
cdef int a, b, c
means: "use C type 'int' for a, b and c". This changes the value range of
the variables and makes various operators overflow if the value range is
too tight. That's what users must expect when they assign a numeric type
with a restricted value range.
It's also ok if an operator behaves different for an "int" and an "unsigned
int", because both are explicitly declared as such by the user in order to
make exactly the distinction between an unsigned and a signed type.
It's a very different thing if an operator changes its target value range
because of a type declaration that is perfectly suited to match the
expected target range. A C "int" can represent all values that
"some_pyint%5" can take. The same applies to a Python int target and a C
"unsigned int" target because of the semantics of the % operator in Python.
All three are equivalent from the point of view of this operation. Here, it
is simply not true that the user "must" expect the semantics to change when
typing the variable. Instead, it comes as a side effect, because it's not
the variable with its assigned value range that imposes these semantics,
but the operator itself, which simply behaves different when working on
exactly the same input. And it behaves different in a place that can be
very hard to find, as it's extremely unlikely that users back this kind of
code by unit tests.
Personally, I think Cython should not be designed to enforce unexpected
code behaviour, and definitely not by default.
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev