Dag Sverre Seljebotn wrote:
> The argument against changing the default is simply that there is
> another option which is much closer to Python semantics (and IMHO more
> user friendly as the user don't have to care about declaring "not None"
> manually).
>
> Java has had decent "None" behaviour for ages using control flow
> analysis, so it can definitely be done.
Java is a far more static language (though I guess we're talking about
static Cython anyway).
> As Robert says, it is just about
> moving the check (that should happen at some point anyway) to the point
> of first attribute access in a code path and then raise the exception
> there, just like Python would.
This sounds simple enough, but would there really be a limited
performance hit? I'm a bit over my head here, but in something like this:
cdef func(MyType x):
...
for i in a_really_big_loop:
if a_conditional:
do_something_with( x )
wouldn't you need to check if x were None inside that loop? Or could you
know that it _may_ be used, and therefor check before the loop?
If so, then great, but the current default really is broken.
Dag Sverre Seljebotn wrote:
> It's seems very complicated to hold a
> Cython tutorial where I have to explain that "MyType myvar" means
> something else for function arguments than in local variable or class
> field declarations.
as a newbie, yes, you are right that is confusing, but...
> If you want to propose that
>
> cdef X x = None
>
> is also disallowed, then that's something else entirely.
You mean that is allowed? I wouldn't have expected that! I guess I've
never tried it, nor been bitten by it, but yes, I'd think that would be
illegal.
For just that the same reason -- I'm statically typing so that I can
count on an object being a certain type -- if I have to write "is None"
checks all over the place, what's the point? And anything that can cause
a segfault is a bug, period.
so, can I now do:
cdef f( int x ):
....
def myfunc(x, y):
cdef int z
...
z = x
...
f( z )
and pass in None for x, and have f( z ) get None? If so, might it crash?
and if not, where is it caught?
I guess it comes down to this, from this newbie's perspective:
If I type a variable, the code should not crash if I pass in something
else, anything else, it should coerce or fail with an exception, unless
I _explicitly_ tell Cython that it could be something else, in which
case, I'd better have written the code to handle that.
> Anyway: It's 2 vs. 2 at this point
I really don't care if anyone is counting my "vote" or not, this sort of
decision shouldn't be made by majority choice anyway.
And I think I am less of a "user" than all of you, but more of a newbie,
which means I may very well not understand important subtleties.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
[email protected]
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev