2016-07-28 17:03 GMT+02:00 Stefan Glienke <sglie...@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
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel