Recent

Author Topic: Generics - correct syntax  (Read 4208 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 16190
  • Censorship about opinions does not belong here.
Re: Generics - correct syntax
« Reply #15 on: April 23, 2024, 05:40:59 pm »
Did you actually read the documentation? Because the differences are well documented.
I smell a bit of too lazy to read...
It is chapter 8 of the language reference guide... >:D

If there's anything not clear, report back. Otherwise disappear in a corner of shame.
You can come out of the corner if Michael says so.... :D ;D :o
« Last Edit: April 23, 2024, 05:52:57 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

VisualLab

  • Hero Member
  • *****
  • Posts: 575
Re: Generics - correct syntax
« Reply #16 on: April 24, 2024, 01:32:11 pm »
Did you actually read the documentation? Because the differences are well documented.
I smell a bit of too lazy to read...
It is chapter 8 of the language reference guide... >:D
You can come out of the corner if Michael says so.... :D ;D :o

Of course. But I don't think I understood much of this description :)

If there's anything not clear, report back. Otherwise disappear in a corner of shame.
You can come out of the corner if Michael says so.... :D ;D :o

It's good to know who is an expert on generic types in Free Pascal and who to ask if anything is unclear :)

Thaddy

  • Hero Member
  • *****
  • Posts: 16190
  • Censorship about opinions does not belong here.
Re: Generics - correct syntax
« Reply #17 on: April 24, 2024, 01:48:32 pm »
The current expert in generics from the core team is PascalDragon (as well as Florian)
The absolute expert in documentation is Michael van Canneyt (MvC), always has been.

All are accessible for questions, even stupid ones... 8-) O:-)
If I smell bad code it usually is bad code and that includes my own code.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: Generics - correct syntax
« Reply #18 on: April 25, 2024, 09:49:09 pm »
The definition of what I have in the FPC 3.2.2 is this
Code: Pascal  [Select][+][-]
  1.  generic TCreateChildList<T: TObject> = class(specialize TFPGObjectList<T>)
  2.  
                                      ^^^^^^^^^
AS you can see, it does not work correctly this way. Doing so hides the field and I can only assume is due to the fact that
the Class that is being introduced as the type is a CLASS and here we have  a TOBJECT for which the version compiler I am using does not seem to understand.

Hides what field? Please don't do code snippets when asking about problems, but please provide complete, self contained examples that I can simply stuff into the compiler or understand completely by looking at it.

Code: Pascal  [Select][+][-]
  1.  generic TCreateChildList<T: TObject> = class(specialize TFPGObjectList<T>)
  2.  

When and in what combinations can the keywords generic and specialize be used together, and when should they be used separately? Is there documentation detailing the use/application of these keywords when defining and using generic types in your code? So far, I have used the Delphi mode (most often) or, to a limited extent, the ObjFpc mode with the above-mentioned keywords. I have the impression that at this point the readability and clarity of Object Pascal is approaching the proverbial "readability and clarity" of some C++ mechanisms (that is, the mechanisms are useful, but their writing in the code is unclear and ill-considered, resulting in the impression of gibberish <- note in brackets applies to C++).

The generic keyword is required when you declare a generic type or function/method (in the later case in front of the function/procedure).

The specialize keyword is required when you do a specialization of a generic type (be it as part of a type-declaration or inline). The keyword is always part of the type name itself, so if you have other types or units they are before the specialize keyword.

 

TinyPortal © 2005-2018