[fpc-pascal] Optional param modifier

Ryan Joseph ryan at thealchemistguild.com
Sat Apr 13 22:34:56 CEST 2019

> On Apr 13, 2019, at 3:58 PM, Martin Frb <lazarus at mfriebe.de> wrote:
> You misread me. I am sure inadvertently, but still. You advertised that this feature you desire was to fulfil two purposes. One of which you named to be documentation. Or as you described, the elimination of the need to look through copious amounts of implementation, or in other cases pages of documentation.

I really don’t disagree with you that much since my proposal is minor it has a minor benefit also. The system frameworks on Mac have used empty macros to the same effect so clearly comments work also. i.e.

IOHIDDeviceRef _Nullable IOHIDDeviceCreate(
                                CFAllocatorRef _Nullable        allocator,
                                io_service_t                    service)

I appreciate Apple added those but we could do the same in Pascal with macros.  The engineers at Apple clearly thought the problem was big enough to add it into their new language (Swift) and at least for pointers I agree it’s nice.

> Well, as far as the "optional" part goes, the benefits of it will be fairly limited. Object variables occur in many places, and all of them can have the nil value, and the compiler has no idea if you did the check.
> You pick a tiny subset of those cases, and attempt to add protection to it. Given the gain (or rather absence of it, according to the microscopic size of that subset) the effort (and chance of false positives) is not worth it.

I’m not sure it’s possible to implement without having side effects. Just floating out the idea.

I can find many hundreds of examples like the one above in the Cocoa frameworks since Apple retroactively added them in. I don’t understand why you think this is a minor subset of cases. Btw, they added the macros into the Objective-C headers so the Swift parser could correctly interpret them as optional types (denoted with the ? symbol if you’re familiar with Swift).

Anyways, not a single person thought this was a good idea so I’ll leave it be. :)

	Ryan Joseph

More information about the fpc-pascal mailing list