Recent

Author Topic: What is the difference between the new ADVANCED RECORD and the old OBJECT?  (Read 30734 times)

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #15 on: September 30, 2018, 03:25:54 pm »
Quote
One often has different records with a common header.
Here base objects which will be inherited by specialized objects are convenient. For many cases classes (TObject descendants) have too much not needed overhead so "old style" objects fit well.

Yeah, or just read the general header and a separate header for the extensions. These (doutbful!) cornercases are not really motivations IMHO to keep a complete object model running.
Did you ever made a compiler for example? OK, a compiler is maybe a cornercase but it's lists are full of header-paydata structures, often even multi level.
Quote
In MSElang "object" and "class" are almost the same. "class" instances are always allocated on heap and provide implicit pointer dereference. "object" is  instantiated as stack- or global-variable or on heap if the "object" has a constructor and a destructor, see
https://gitlab.com/mseide-msegui/mselang/wikis/home/mselang_objects
MSElang objects and classes can have variant parts, classes can inherit from objects.

If I would start over, that's probably what I would do, with one exception. I would leave objects pure structures, so no VMT (and thus probably no virtual).

One of the things I hate most about TP objects, is that you can't immediately see if it is a pure record or an object.
In MSElang the [virtual] object/class header attachment defines it. There is no VMT without [virtual].

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #16 on: September 30, 2018, 03:29:49 pm »

Did you ever made a compiler for example? OK, a compiler is maybe a cornercase but it's lists are full of header-paydata structures, often even multi level.

I'm currently working on the chm compiler. While not a compiler in the classic sense, it has a lot of binary internal structures, including B+trees. I have dabbled with compilers, interpreters and expression evaluators in the past.

Quote
In MSElang the [virtual] object/class header attachment defines it. There is no VMT without [virtual].

(and the second annoyance about TP object btw is the manual pointer declaration for objects. I find it annoying even in C++ where you don't have to constantly declare it. The common case should be easy, and shouldn't be hampered by a corner case.)

If we ever align advanced records to class in the same way, something like that could solve that yes. Though I would lean towards simply forbidding vmt beyond class level.

« Last Edit: September 30, 2018, 03:36:31 pm by marcov »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #17 on: September 30, 2018, 04:29:25 pm »
To mention another important difference between object and record that also was (aside from Delphi compatibility) the main reason to add methods to records in the first place: advanced records can contain operator overloads as part of them (in comparison to global operator overloads) that then can be used inside a generic declaration.

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #18 on: September 30, 2018, 05:30:13 pm »
(and the second annoyance about TP object btw is the manual pointer declaration for objects.
I don't understand. What do you mean with "manual pointer declaration for objects"?
Quote
If we ever align advanced records to class in the same way, something like that could solve that yes. Though I would lean towards simply forbidding vmt beyond class level.
Why not universal and orthogonal? Also classes without VMT have it's use, MSElang supports it.
Quote
To mention another important difference between object and record that also was (aside from Delphi compatibility) the main reason to add methods to records in the first place: advanced records can contain operator overloads as part of them
In MSElang operator overloading is also done in objects/classes with the [operator=] method attachment.
https://gitlab.com/mseide-msegui/mselang/wikis/home/mselang_objects#operator

ASerge

  • Hero Member
  • *****
  • Posts: 2240
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #19 on: September 30, 2018, 07:51:21 pm »
First there were record, procedures and functions.
Next, with the emergence of OOP, there were objects.
Next, Borland has introduced classes in which there are additional opportunities. And to force everyone to switch to a new way of declaration, a objects was sign as deprecated.
Later, when it was necessary to merge fields and methods again, it was already inconvenient to revive objects declared as deprecated. And decided to expand records.
And, accordingly, all the new features have tried to do only for records, skipping the implementation for objects, so that they correspond to the previously established policy. And either intentionally made mistakes in the support of old objects, or rather greatly inflated random errors to convince not to use objects.
If we compare records and objects and classes in in FPC now, then

FeatureRecordObjectClass
Encapsulation (combining data and methods + hiding visibility)YesYesYes
InheritanceNoYesYes
Class constrcutor and destrutorYesYesYes
Polymorphism (virtual methods)NoYesYes
Memory allocationStackStackHeap
Operator overload (global)YesYesYes
Operator overload (in type only)YesNoNo
Type helpersYesNoYes
Virtual constructors, class referenceNoNoYes
It should be noted some inconvenience of objects.
If it declares virtual methods, its size increases for storage of VMT (records not containing VMT, size not changed, classes always has VMT, size not changed).
To make virtual methods work, you must define a constructor and call it (the constructor is required for classes).

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #20 on: September 30, 2018, 08:47:00 pm »
A further difference between advanced records and objects/classes is the possibility of advanced records having variant parts (with or without methods).
As far as I can see the keywords "procedure" and "constructor" can be used interchangeably in advanced records. Is there in fact any difference between them in this case?

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #21 on: October 01, 2018, 07:05:57 am »
If we compare records and objects and classes in in FPC now, then
This nice comparison table should end up in a wiki...
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #22 on: October 01, 2018, 07:38:17 am »
If we compare records and objects and classes in in FPC now, then
This nice comparison table should end up in a wiki...
I concur with the above.  Very nicely done Serge.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #23 on: October 01, 2018, 08:01:43 am »
@ASerge
Don't forget management operators for records. (3.2+)
Also note that advanced records do have a VMT if these are used.
« Last Edit: October 01, 2018, 08:37:34 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #24 on: October 01, 2018, 09:26:11 am »
Don't forget management operators for records. (3.2+)
Also note that advanced records do have a VMT if these are used.
Thanks for the update, Thaddy
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

JernejL

  • Jr. Member
  • **
  • Posts: 92
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #25 on: October 01, 2018, 12:09:51 pm »
So, nowadays, why should I choose advanced records instead of object type?

Record routines in FPC inline better than object methods (from my experience)
Memory alignment control for structures (plus very fast read & write, you can just write and read it to Tstream)
Bit packed records are possible too, when dealing with specific limitations or special projects.
Easier allocation for some very fast purposes (array of records can be allocated with just a simple setlength call)
Faster (no RTL overhead).
No constructors needed in variables, just declare & call routines directly on it.
 
« Last Edit: October 01, 2018, 12:34:53 pm by JernejL »

Awkward

  • Full Member
  • ***
  • Posts: 135
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #26 on: October 01, 2018, 12:44:02 pm »
Jernel, objects are like records can be used without constructors, with easy allocation, memory alignment. When records will have inheritance (like in Oberon for example), MAYBE objects will be much less usable. But now objects still have their own area.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #27 on: October 01, 2018, 01:21:19 pm »
@ASerge
Don't forget management operators for records. (3.2+)
Also note that advanced records do have a VMT if these are used.
But unlike for objects that is not part of the record "instance", but only part of the Init RTTI metadata, thus per type.

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #28 on: October 01, 2018, 02:37:10 pm »
@ASerge
Don't forget management operators for records. (3.2+)
Also note that advanced records do have a VMT if these are used.
But unlike for objects that is not part of the record "instance", but only part of the Init RTTI metadata, thus per type.
Thanks for adding the difference...
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

ASerge

  • Hero Member
  • *****
  • Posts: 2240
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #29 on: October 01, 2018, 08:11:52 pm »
FeatureRecordObjectClass
Encapsulation (combining data and methods + hiding visibility)YesYesYes
InheritanceNoYesYes
Class constrcutor and destrutorYesYesYes
Polymorphism (virtual methods)NoYesYes
Memory allocationStackStackHeap
Operator overload (global)YesYesYes
Operator overload (in type only)YesNoNo
Type helpersYesNoYes
Virtual constructors, class referenceNoNoYes
Variant part (case) as c++ unionYesNoNo
Bitpacked (really packing)YesNoNo

Added a variant part and bitpacked. Thanks @howardpc and @JernejL.

 

TinyPortal © 2005-2018