[fpc-devel] "Default" discussion for SmartPointers etc
hnb.code at gmail.com
Thu Jul 28 18:47:50 CEST 2016
2016-07-28 17:03 GMT+02:00 Stefan Glienke <sglienke at dsharp.org>:
> I agree with Michael here. While in Spring4D our nullables have the
> operator in both directions in retrospective I think it's not a good idea
> the nullable<x> -> x conversion should be explicit (with the possibility to
> raise an explicit exception - not an AV) and for sure not be faked by the
> operator because a nullable is not a reference type in my book even if it
> can be
> null (err nil?) That btw leads to another question - is the "null" state
> to nil - or is it something different. So a nullable is kind of both
> things, it
> can be nil/null but if not it contains the value but does not point to it
> cannot/should not be deferenced. C# for example requires a hard cast or
> the call
> to .Value to get the underlying value from a nullable with the possibility
> throw a InvalidOperationException if it has no value.
Remember that we working not in .NET environment, Pascal has assembler,
pointers and other cool stuff, and I think that we need different approach
adjusted to highly optimized needs. Explicit conversion still exist.
Default field is blazing fast solution and it covers many needs (not
nilable types only). I don't want 1:1 copy from C# -,-
> FWIW if you make it a new language construct I actually would prefer
> of <type>" which is consistent with "array of <type>" or "set of <type>".
aside from the syntax I see nilable types as new type kind called: proxy.
Same family as smart pointers and ARC objects, that means new unified
ProxyOwnerType: TypeInfoPtr; // maybe ProxyContainerType is
better name? It points to type information of record
TProxyType = (
ptCustom, // proxy object defined by user, declared as var x:
ptNilable, // declared as var x: nilable/nullable Integer
ptStrong, // declared as var x: strong TObject;
ptWeak, // declared as var x: weak TObject;
ptUnretained); // declared as var x: unretained TObject;
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel