[fpc-pascal] Feature Announcement: Function References and Anonymous Functions

Michael Van Canneyt michael at freepascal.org
Sat May 28 13:39:52 CEST 2022



On Sat, 28 May 2022, Hairy Pixels via fpc-pascal wrote:

>
>
>> On May 28, 2022, at 2:06 PM, Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> 
>> Ah...
>> 
>> The desire to make a programming language terse and unreadable as a consequence.
>> If you want that, use C#, Javascript or one of the ubiquitous languages for bracket fetishists.
>> Scala & Rust top the bill in terms of unreadability.
>> 
>> So no, that's a "No pasarán".
>
> Well that’s been my experience using both Swift and C# frequently over the
> last couple years that you don’t actually need to see the full function
> declaration in most instances because it’s inferred from the context.

I'm happy for the computer that it can infer things from the context in
milliseconds. Really, I stand in awe...

And I'm sure it finds these very understandable (live examples):

[s: string]: ((s: string, cb: (done: any) => void) => void) & ((cb: (done: any) => void) => void) & {only: any, skip: any};
load: (url: string, onLoad: (object3D: THREE.Object3D) => void, onProgress?: (progress: ProgressEvent) => void, onError?: (event: ErrorEvent) => void) => void;
function comp<A, B, C, D>(c: (c: C) => D, b: (b: B) => C, a: (a: A) => B): (a: A) => D;
function comp<A, B, C, D, E>(d: (d: D) => E, c: (c: C) => D, b: (b: B) => C, a: (a: A) => B): (a: A) => E;
singleton = _.memoize(<T>(classInstance: new () => T) => new classInstance());
function cacheGetter(judgeFunc: () => boolean, returnCacheValueFunc: () => any, setCacheFunc: (returnVal: any) => void): (target: any, name: any, descriptor: any) => any;

However, I as a human have a brain that works at lower clock cycles, but even so 
I like to see at a glance what is intended without having to think too long on 
'what on earth could missus X have meant here ?'.

That means providing a little more context/structure, and keeping the door
firmly closed for syntax that allows absurd monstrosities as the things above. 
(and preferably lock it, take out the key and throw it away while we're at it)

This is - incidentally - also why I think pascal should never allow type definitions
in function arguments.

For similar reasons I deplore the popularity of YAML or markdown, which all
too often provide too little structure to grasp what is meant. 
By contrast XML is too much cruft, but e.g. JSON strikes a good balance.

Programming languages are meant for humans, not for computers.

If it were up to the computer, we'd probably simply write out programs as sequences
of 0-s and 1-s. Guaranteed to be the shortest notation, but good luck trying
to make sense of that as a human. I suspect punched cards are a thing of the past
just for this reason.

The downside is that every human has his likes and dislikes.

But, if you actually prefer the above syntax to the more verbose pascal, you're in luck: 
There are many languages that will allow you to knock yourself out =-)

Michael.


More information about the fpc-pascal mailing list