[fpc-devel] "Default" discussion for SmartPointers etc
Michael Van Canneyt
michael at freepascal.org
Tue Jul 26 15:09:06 CEST 2016
On Tue, 26 Jul 2016, Maciej Izak wrote:
> Finally I have a working implementation (not published yet) of Smart
> Pointers/ARC objects and Nullable (Nilable?) types. I think is worth to
> discuss a little about new "default modifier" (which is strictly related to
> mentioned structures). If needed I can correct details.
> As you know (or not) all is based on new modifier - "default" for fields.
> Overriding operators like "." or "^" is complicated and not obvious in
> Pascal world.
> The "default" modifier is inspired by "default" modifier for indexed
> properties. All of my work is (I hope so) natural for Pascal language. All
> FPC tests pass fine (phew!). The idea is quiet simple:
> "If all fails - try to use default field".
> Example implementation of SmartPointers and SmartObjects available at:
> https://github.com/maciej-izak/PascalSmartPointers (see OUTPUT on the end
> of each of file)
> Tests (very good way to see how it works. NOTE: I need to add few other
> tests for functions with var/const/out, "for in do" loop and for arrays and
> indexed properties - help with additional tests is welcome):
> The way how to obtain pointer can be a little confusing for most of Pascal
> programmers. Anyway nothing new for Pascal language. In Pascal we have
> little known @@ operator to get pointer to variable which handle pointer to
> procedure/function. For records with "default field" @ means "get pointer
> to default field" and @@ means "get pointer to record".
Very nice job indeed.
I can see a lot of potential in this for ORM implementations, where IS NULL
is always a difficult concept.
As for ARC: I think this is a difficult topic, which should better be
discussed in a separate thread.
More information about the fpc-devel