Recent

Author Topic: Nested declarations inside advanced record  (Read 24542 times)

440bx

  • Hero Member
  • *****
  • Posts: 5077
Re: Nested declarations inside advanced record
« Reply #15 on: January 09, 2025, 05:38:46 pm »
Since the inception of Pascal.
and then came the Big Bang because there was nothing before Pascal.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

simone

  • Hero Member
  • *****
  • Posts: 648
Re: Nested declarations inside advanced record
« Reply #16 on: January 09, 2025, 06:07:05 pm »
All records can be nested, advanced or not. Simple answer and correct.
Since the inception of Pascal.

Thaddy, I'm not sure about this. It seems to me that "conventional" records cannot have nested declarations like the ones in my second program in the first post. If you remove {$modeswitch advancedrecords} the program won't compile.
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 16653
  • Kallstadt seems a good place to evict Trump to.
Re: Nested declarations inside advanced record
« Reply #17 on: January 09, 2025, 06:59:57 pm »
Simple records can be members of higher records. That has always been the case.
You can generalize this to records can be members of records. Advanced or not.
If you give me a proper example where it fails in your view, I am happy to correct it.
« Last Edit: January 09, 2025, 07:02:19 pm by Thaddy »
But I am sure they don't want the Trumps back...

simone

  • Hero Member
  • *****
  • Posts: 648
Re: Nested declarations inside advanced record
« Reply #18 on: January 09, 2025, 07:03:20 pm »
Certainly, but the fact that a record can have fields that are also of the record type is a very different concept from that of nested declarations.

Try to compile this program:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$mode objfpc}
  3.  
  4. type
  5.  
  6.   { MyRec }
  7.  
  8.   TMyRec=record
  9.     private
  10.       const
  11.         C=5;
  12.       var
  13.         X, Y : integer;
  14.       type
  15.         TB=integer;
  16.     public
  17.       procedure Proc;
  18.   end;
  19.  
  20. { MyRec }
  21.  
  22. procedure TMyRec.Proc;
  23. begin
  24.  
  25. end;
  26.  
  27. begin
  28. end.
  29.  
« Last Edit: January 09, 2025, 08:06:02 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

Warfley

  • Hero Member
  • *****
  • Posts: 1870
Re: Nested declarations inside advanced record
« Reply #19 on: January 09, 2025, 08:21:52 pm »
Try to figure this out.. what critical characteristic of OOP do advanced records showcase ? 

reply when AND IF you figure out the answer.   Ask ChatGPT, it might be able to find the answer for you (and Thaddy.)

The union of data and code. But whats your point? Note that the union of code and data is required for OOP but not sufficient. The same is true for closures yet closures are not considered OOP :)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5904
  • Compiler Developer
Re: Nested declarations inside advanced record
« Reply #20 on: January 09, 2025, 09:06:58 pm »
Therefore, should I assume that nested declarations of types and constants are also possible with advanced records?

Thanks in advance.
In theory it should because objects and classes are just extensions of advanced records.

Advanced records are the "seed" of OOP.  That's where it all starts.  Conceptually, Classes/Objects = Advanced records + inheritance + polymorphism.

For a long time records in Pascal-based languages did not support type or constant declarations inside them (aside from anonymous types as part of field declarations). They were only ordered collections of fields and only Delphi 2007 (I think) introduced the concept of advanced records which allow to have type and constant declarations as well as methods declared in them.

440bx

  • Hero Member
  • *****
  • Posts: 5077
Re: Nested declarations inside advanced record
« Reply #21 on: January 09, 2025, 09:19:37 pm »
<snip>   as well as methods declared in them.
THAT is the seed of OOP.  That's encapsulation and without it there is no OOP.

It looks like some people think that if it didn't start in the Pascal language then it must not exist.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Warfley

  • Hero Member
  • *****
  • Posts: 1870
Re: Nested declarations inside advanced record
« Reply #22 on: January 09, 2025, 09:27:40 pm »
THAT is the seed of OOP.  That's encapsulation and without it there is no OOP.

It looks like some people think that if it didn't start in the Pascal language then it must not exist.

So closures are OOP? If so, congrats lisp was already OOP in the 50s

PascalDragon

  • Hero Member
  • *****
  • Posts: 5904
  • Compiler Developer
Re: Nested declarations inside advanced record
« Reply #23 on: January 09, 2025, 09:36:50 pm »
<snip>   as well as methods declared in them.
THAT is the seed of OOP.  That's encapsulation and without it there is no OOP.

If one thinks of records as the seed of OOP then one generally assumes records to be without methods, because records represent the state while the methods represent changes of the state and that plus inheritance is what OOP adds.

It looks like some people think that if it didn't start in the Pascal language then it must not exist.

Though Pascal was at least among the first to introduce the concept of records. ;)

440bx

  • Hero Member
  • *****
  • Posts: 5077
Re: Nested declarations inside advanced record
« Reply #24 on: January 09, 2025, 09:46:05 pm »
It isn't about records... it is about the pairing of data and procedures in a dedicated structure which is what advanced records are and bring to the table.  That pairing is the door to OOP, without that, there is no OOP.

The name that pairing is given is irrelevant.  It's the concept's existence that matters, regardless of name.   Once you have that, you can extend the concept with inheritance and polymorphism.  Without encapsulation, you cannot have those and without those there is no OOP.

OMG !!!
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5904
  • Compiler Developer
Re: Nested declarations inside advanced record
« Reply #25 on: January 09, 2025, 10:07:15 pm »
It isn't about records... it is about the pairing of data and procedures in a dedicated structure which is what advanced records are and bring to the table.  That pairing is the door to OOP, without that, there is no OOP.

The name that pairing is given is irrelevant.  It's the concept's existence that matters, regardless of name.   Once you have that, you can extend the concept with inheritance and polymorphism.  Without encapsulation, you cannot have those and without those there is no OOP.

To be fair: that was not obvious from what you had written.

Warfley

  • Hero Member
  • *****
  • Posts: 1870
Re: Nested declarations inside advanced record
« Reply #26 on: January 09, 2025, 11:26:06 pm »
OOP generally requires 4 properties:
1. Coupling of data (fields) and functionality (methods) into single entities (objects)
2. Types themselves are objects (of meta types) that have their own data and methods (static/class methods)
3. Inheritance and the ability to extend existing data types with additional data and/or functionality
4. Dynamic message dispatching within the object through runtime polymorphism (through virtual methods)

If any of these 4 is not satisfied, a language is generally not considered OOP. That's why for example Go is not considered an object oriented language, even though they cover 1. And 4.

Saying any one of them is the "seed" of OOP is not quite true as you need all 4 in combination for OOP. Many langues have similar properties, e.g. functional languages like Haskell or Lisp usually also combine data and code, and data types are usually also objects in the language. Infact Smalltalk was heavily influenced by Lisp. But because they don't provide the other properties it's not OOP

440bx

  • Hero Member
  • *****
  • Posts: 5077
Re: Nested declarations inside advanced record
« Reply #27 on: January 09, 2025, 11:33:31 pm »
Saying any one of them is the "seed" of OOP is not quite true
I am not correcting you for your benefit but for others who may be reading this. 

Encapsulation is the _seed_ of OOP because THAT is what enables polymorphism and inheritance the way it's done in OOP.   The binding of code and data is what allows those extensions to exist.  Encapsulation is the distinguishing feature of what is called advanced records in Pascal that's what makes them the seed of OOP.

It's irrelevant that advanced records appeared in the language after objects and classes, the concept of encapsulation is  what matters.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Warfley

  • Hero Member
  • *****
  • Posts: 1870
Re: Nested declarations inside advanced record
« Reply #28 on: January 10, 2025, 12:08:30 am »
Except.it doesn't, look at the Berkeley sockets api, it's a c API so not OOP, yet it also uses polymorphism based upon the passed data types of the sockaddr struct. If you pass a sockaddr_in to bind it will call the respective ipv4 functionality, if you pass a sockaddr_in6 to bind it will execute the respective code for ipv6.
Similarly if you call send on a UDP socket the UDP packet will be sent, while if you call it on a tcp socket you write data to a stream. Polymorphism over the data type without OOP

I know that you are quite familiar with the windows API, and the windows API does runtime polymorphism based on the data type passed all the time. So how can you claim it's only possible in OOP?

Infact polymorphism based on the data type passed, using common prefixes for data types is a well established practices long before OOP became a thing. Nothing in OOP is actually new and you can't boil OOP down to a single design decision, it's the combination of the 4 aspects above.
« Last Edit: January 10, 2025, 12:16:59 am by Warfley »

Khrys

  • Full Member
  • ***
  • Posts: 177
Re: Nested declarations inside advanced record
« Reply #29 on: January 10, 2025, 07:44:56 am »
So sorry
You are rather sorry... you got that right.

[...]

reply when AND IF you figure out the answer.   Ask ChatGPT, it might be able to find the answer for you (and Thaddy.)

There is one thing that has been clearly re-enforced by a select few forums participants and that is that, some people are surprisingly resistant to acquiring knowledge.  I guess it might have something to do with the fact that most of them seem to believe they know everything and were born that way (or got their "infinite" knowledge from reading FPC source code <chuckle>.)

The conclusion is: the results, which are usually very poor, are not worth my time.

[...]

Thaddy is _always_ right... haven't you figured that out yet ? ... and he is not the only one.

I find this kind of passive-aggressive condescension very irritating. Maybe you should take a look in the mirror before calling everyone who disagrees with you a stubborn know-it-all.
I do not mean to discredit your knowledge; your contributions to this forum contain very valuable information. But please consider turning down the smugness & sense of self-superiority a bit.

 

TinyPortal © 2005-2018