Recent

Author Topic: Objects vs advanced records  (Read 762 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 355
Objects vs advanced records
« on: October 16, 2025, 05:33:45 pm »
Hello.

What is preferable to use old-school object or advanced records? What advantages and disadvantages?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Thaddy

  • Hero Member
  • *****
  • Posts: 18306
  • Here stood a man who saw the Elbe and jumped it.
Re: Objects vs advanced records
« Reply #1 on: October 16, 2025, 05:40:24 pm »
objects support OOP although different syntax from classes.
records do not support OOP, no inheritance, not even with advanced records.

In general I use records for new code (with the exception of KOL) and use objects if I need a stack-oriented approach because then objects can be much, much faster than classes.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Warfley

  • Hero Member
  • *****
  • Posts: 2020
Re: Objects vs advanced records
« Reply #2 on: October 16, 2025, 05:41:21 pm »
Objects have inheritance and virtual methods. Records have variant parts, can overload operators and have management operators.

So if you need inheritance go with objects, for everything else records are probably the more versatile choice

Awkward

  • Full Member
  • ***
  • Posts: 154
Re: Objects vs advanced records
« Reply #3 on: October 16, 2025, 05:58:41 pm »
Question is why developers still didn't realize things what we have in records, even helpers for objects?

LemonParty

  • Sr. Member
  • ****
  • Posts: 355
Re: Objects vs advanced records
« Reply #4 on: October 16, 2025, 07:01:31 pm »
Are there a managment operators for objects?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Thaddy

  • Hero Member
  • *****
  • Posts: 18306
  • Here stood a man who saw the Elbe and jumped it.
Re: Objects vs advanced records
« Reply #5 on: October 16, 2025, 07:20:09 pm »
Are there a managment operators for objects?
No, and they are not necessary because objects have constructors and destructors. Contrary to records, objects are not a flat model.
The way that works is a bit quirky to anyone under 55, but an established way that the old TP5.5 programmers are familiar with.
« Last Edit: October 16, 2025, 07:23:18 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Warfley

  • Hero Member
  • *****
  • Posts: 2020
Re: Objects vs advanced records
« Reply #6 on: October 16, 2025, 07:58:44 pm »
Question is why developers still didn't realize things what we have in records, even helpers for objects?
Simple, objects aren't really touched. The only time objects get new features is if those are part of the shared functionality between objects and classes (or even records, all three share a lot of code in the compiler) and objects basically get that "for free".

There is no interest by the core developers to add change anything in objects that goes beyond that.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6184
  • Compiler Developer
Re: Objects vs advanced records
« Reply #7 on: October 16, 2025, 10:33:43 pm »
Question is why developers still didn't realize things what we have in records, even helpers for objects?
Simple, objects aren't really touched. The only time objects get new features is if those are part of the shared functionality between objects and classes (or even records, all three share a lot of code in the compiler) and objects basically get that "for free".

There is no interest by the core developers to add change anything in objects that goes beyond that.

Well, I do plan to add helpers for objects, but mainly because I want to allow helpers for all types in the end.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11793
  • Debugger - SynEdit - and more
    • wiki
Re: Objects vs advanced records
« Reply #8 on: October 16, 2025, 11:04:41 pm »
Well, I do plan to add helpers for objects, but mainly because I want to allow helpers for all types in the end.

What about generic constraints?
Code: Pascal  [Select][+][-]
  1. //Instead of
  2. generic Foo<X: class> = class(X) {...} end;
  3. // Allow
  4. generic Foo<X: object> = object(X) {...} end;
  5.  

PascalDragon

  • Hero Member
  • *****
  • Posts: 6184
  • Compiler Developer
Re: Objects vs advanced records
« Reply #9 on: October 16, 2025, 11:33:20 pm »
Well, I do plan to add helpers for objects, but mainly because I want to allow helpers for all types in the end.

What about generic constraints?

While I do plan to extend generic constraints I don't intend to add constraints for objects.

 

TinyPortal © 2005-2018