Recent

Author Topic: Advantages/disadvantages of advanced records over conventional records.  (Read 1345 times)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 733
I can see how the "advanced record" type makes my code more readable by combining a conventional "record" with the functions and procedures that are used to work with it into a single entity (not quite an object, but close).  But do I pay any price in memory or performance by converting my conventional records into advanced records?   What are the advantages and disadvantages of using the advanced record type vs. the "old fashioned" approach?

I have a unit which includes {$modeswitch advancedrecords} and contains both conventional record types and advanced record types.  Does the compiler distinguish between them, or does it promote all records to advanced records?  And if so, at what price?

PascalDragon

  • Hero Member
  • *****
  • Posts: 6359
  • Compiler Developer
Re: Advantages/disadvantages of advanced records over conventional records.
« Reply #1 on: December 22, 2022, 07:17:15 am »
There isn't a difference between “advanced records” and “normal” records as far as the compiler is concerned. The modeswitch AdvancedRecords only enables the parsing of visibility sections, methods, operators and properties inside records, anything else is the same and already there.

The only real disadvantage of the modeswitch is if you have legacy code that uses keywords like private or property cause you either need to rename them or prefix them with & to escape them.

And main advantage of advanced records: if you declare operator overloads they are available inside generics as well while global operator declarations for a record are not.

Thaddy

  • Hero Member
  • *****
  • Posts: 18797
  • Glad to be alive.
Re: Advantages/disadvantages of advanced records over conventional records.
« Reply #2 on: December 22, 2022, 08:41:36 am »
I find the biggest advantage that operations (not operators perse) on the record instance or the record type can be closely coupled to the record data or the record type itself.
« Last Edit: December 22, 2022, 11:33:49 am by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 733
Re: Advantages/disadvantages of advanced records over conventional records.
« Reply #3 on: December 22, 2022, 10:28:13 pm »
Thank you for the insight.  I too see the tighter coupling between operations and record data, in terms of name-space clarity if nothing else, as a big advantage.  Especially  if there's no run-time overhead involved.  For me, an important argument for pascal over other languages has always been its readability, and the advanced record seems to enhance that.

 

TinyPortal © 2005-2018