[fpc-devel] "Default" discussion for SmartPointers etc
Maciej Izak
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
> implicit
> operator in both directions in retrospective I think it's not a good idea
> and
> 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
> deref
> 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
> equal
> 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
> thus
> 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
> to
> 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
> "nullable
> 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
TTypeData entry:
tkProxy:
(ProxyType: TProxyType;
ProxyOwnerType: TypeInfoPtr; // maybe ProxyContainerType is
better name? It points to type information of record
DefaultFieldOffset: PtrUInt;
DefaultFieldType: TypeInfoPtr);
where
TProxyType = (
ptCustom, // proxy object defined by user, declared as var x:
TMySmartPtr<Pointer>;
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;
--
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160728/e0c00503/attachment.html>
More information about the fpc-devel
mailing list