On Apr 13, 2010, at 9:34 AM, Christopher Barker wrote:
> 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?
I think we could avoid the performance hit in most, but not all, cases.
> 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.
The issue is that
cdef X x
and
cdef class Y:
cdef X x
have to provide some kind of default value for x, and None is really
the only option here. This means that None can get essentially
everywhere.
> 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.
Yes, but we haven't managed to fix that one without slowing everything
down yet :)
- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev