Author Topic: New compile time operator "type of" (modeswitch TypeInquiry)  (Read 1261 times)

zamtmn

  • Hero Member
  • *****
  • Posts: 706
Re: New compile time operator "type of" (modeswitch TypeInquiry)
« Reply #15 on: October 06, 2026, 09:40:49 am »
Of course, there are problems, which is why I’m putting this on the forum for discussion. For example, in {$mode delphi}, the signature matching is not checked at all during assignment. if my memory me right.

H₂SO₄

  • Hero Member
  • *****
  • Posts: 518
Re: New compile time operator "type of" (modeswitch TypeInquiry)
« Reply #16 on: October 06, 2026, 09:41:55 am »
The signature is available in the IDE with a single click.

This is about language design. A language that needs specific external tools to become usable is badly designed.

Apart from that, the "single click" you describe requires me to take one hand off the keyboard, move the mouse to the correct location, and finally use both hands input a control-click. After reading the definition, I then need to jump back to where this totally unnecessary indirection interrupted my reading flow.

zamtmn

  • Hero Member
  • *****
  • Posts: 706
Re: New compile time operator "type of" (modeswitch TypeInquiry)
« Reply #17 on: October 06, 2026, 09:46:36 am »
>>This is about language design.
>>A language that needs specific external tools to become usable is badly designed.

but a design that expects the programmer to keep the signature of a function in his head and reproduce it with his hands is no better. It without IDE))

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12820
  • Debugger - SynEdit - and more
    • wiki
Re: New compile time operator "type of" (modeswitch TypeInquiry)
« Reply #18 on: October 06, 2026, 10:16:44 am »
>>This is about language design.
>>A language that needs specific external tools to become usable is badly designed.

but a design that expects the programmer to keep the signature of a function in his head and reproduce it with his hands is no better. It without IDE))

In generic (not on this specific case):

How to you distinguish between "the language needs" and "some people need when using the language"?

Because the latter of the 2 is true for any language, and will keep holding true no matter how much you add.

zamtmn

  • Hero Member
  • *****
  • Posts: 706
Re: New compile time operator "type of" (modeswitch TypeInquiry)
« Reply #19 on: October 06, 2026, 10:29:19 am »
I don’t distinguish it in any way; I’m not smart enough to develop languages. But I use language and run into some problems; sometimes I come up with ideas for solving them.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12820
  • Debugger - SynEdit - and more
    • wiki
Re: New compile time operator "type of" (modeswitch TypeInquiry)
« Reply #20 on: October 06, 2026, 10:54:47 am »
This answer is about the generic language design statement / it is not specific to "type of"
I don’t distinguish it in any way; I’m not smart enough to develop languages. But I use language and run into some problems; sometimes I come up with ideas for solving them.

Well, yes. Been there (and seen plenty of other people having been there). But, very very often [1] when that happens, it happens for reasons that are not fault of the language. Often even it happens due to strength of the language.

Most of us know more than one language. And those language are different. Not just in the keywords, or symbols they have, but in the way you implement things => they can often not be translated one to one. But that is good.

Script language give me a lot of constructs that allow for very quick constructs. Like interpolating into strings, not just vars, but even small bits of code. => great for a throw away script that I write directly on the shell command line. Absolute maintenance horror, for a program that I keep and develop over several decades.

But the moment someone used it, its like chocolate (or a certain brand of crisps) => you had one, your brain goes MORE.

A good language design is not just defined by what it includes, but also by what it intentionally excludes.

And yes, we have InstantFpc. But I would not do my one liner shell script in Pascal. The language was intentionally not designed for that.


[1] There are examples of other cases on this forum, and elsewhere on the net. That is a handful of people, and very specific valid issues. Cound the number of them, compare against the overall amount of Pascal users and the requests outside those very specifics => then while those few have a point, the others fall into "very very often".

Thaddy

  • Hero Member
  • *****
  • Posts: 19978
  • Pointless static linking author
Re: New compile time operator "type of" (modeswitch TypeInquiry)
« Reply #21 on: October 06, 2026, 11:11:15 am »
If you use type of, you still need to provide an instance of that type: it does NOT copy over the body of a function.
Code: Pascal  [Select][+][-]
  1. {$Mode objfpc}
  2. function F1: byte;
  3. begin
  4.   Result := 1;
  5. end;
  6.  
  7. function F2: byte;
  8. begin
  9.   Result := 100;
  10. end;
  11.  
  12. var
  13.   a: type of F1;
  14. begin
  15.   writeln(a);// writes 0, by accident, since it is heap, that is  a bug
  16.   a := F1;// the TYPE needs an IMPLEMENTATION....
  17.   writeln(a);// writes 1;
  18.   a := F2;// the TYPE needs an IMPLEMENTATION....
  19.   writeln(a);// writes 100;
  20. end.
It is nothing more than sugar for procedural variable types.
Code: Pascal  [Select][+][-]
  1. {$Mode objfpc}{$modeswitch classicprocvars+}
  2. type
  3.   TFunc = function:byte;
  4.  
  5. function F1: byte;
  6. begin
  7.   Result := 1;
  8. end;
  9.  
  10. function F2: byte;
  11. begin
  12.   Result := 100;
  13. end;
  14.  
  15. var
  16.   a: TFunc;
  17. begin
  18.   a := F1();// the TYPE needs an IMPLEMENTATION....
  19.   writeln(a());// writes 1;
  20.   a := F2;// the TYPE needs an IMPLEMENTATION....
  21.   writeln(a);// writes 100;
  22. end.
Its implementation goes wrong in two ways:
- type of <procedure> does not work, that is a bug
- functions work somewhat, but an uninitialized pointer works where it should not work. That is also a bug.

« Last Edit: October 06, 2026, 11:24:05 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

PascalDragon

  • Hero Member
  • *****
  • Posts: 6454
  • Compiler Developer
Re: New compile time operator "type of" (modeswitch TypeInquiry)
« Reply #22 on: October 08, 2026, 09:19:40 pm »
Of course, there are problems, which is why I’m putting this on the forum for discussion. For example, in {$mode delphi}, the signature matching is not checked at all during assignment. if my memory me right.

Of course it's checked... 🙄

Code: Pascal  [Select][+][-]
  1. program tprocvar;
  2.  
  3. {$mode delphi}
  4.  
  5. type
  6.   TTest = procedure(aFoo: TObject; aStr: String);
  7.  
  8. procedure Test(aFoo: TObject; aStr: String);
  9. begin
  10.  
  11. end;
  12.  
  13. procedure Test2(aFoo: TObject; aStr: WideString);
  14. begin
  15.  
  16. end;
  17.  
  18. var
  19.   t: TTest;
  20. begin
  21.   t := Test;
  22.   // Error: Incompatible types: got "Test2(TObject;WideString);" expected "<procedure variable type of procedure(TObject;AnsiString);Register>"
  23.   //t := Test2;
  24. end.

 

TinyPortal © 2005-2018