Forum > Suggestions
Are forward declarations really necessary?
TRon:
--- Quote from: Ryan J on February 18, 2024, 01:23:19 pm ---Do you have any links to old discussions?
--- End quote ---
Not from the top of my head. Though a simple search delivered this (hardly a discussion but a stand/viewpoint).
The bugtracker as well as the mailinglist have seen this topic being discussed as well as these forums.
--- Quote ---I'm curious about the topic because it seems like a legit shortcoming of Pascal which maybe it's time to reconsider given modern hardware. Maybe a single pass compiler was the obvious choice in 1980 but I'm not so sure if this is true in 2024.
--- End quote ---
You seem to forget (perhaps ignore ? ;) ) that Free pascal also runs on (exotic and/or older) restricted hardware (the raspberry pi which is recent and can be fairly restricted in its hardware capabilities is a good example of that) but also msx, msdos, etc. You could perhaps argue to use cross-compilation instead but that takes away a lot of (native development) comfort.
Other than that you have (somewhat of) a point but I personally also prefer the very fast single pass compilation times. E.g. I can live with the current limitations (though I prefer current bugs to get eradicated but that is a whole other topic in itself)
PascalDragon:
--- Quote from: Ryan J on February 18, 2024, 01:30:27 pm ---
--- Quote from: PascalDragon on February 18, 2024, 01:19:02 pm ---The language philosophy is “declare before use” and is one of the main principles of Pascal along with “separation of declaration and definition” and we uphold these, because they lead to clearer code.
--- End quote ---
To be clear I'm just talking about resolving types from different units which have circular dependancies, not allowing declaring types in any order. The problem can be fixed but moving all types into a single unit but this cripples what's nice about units.
--- End quote ---
For Objective Pascal Jonas had added the concept of formal declarations (TSomeType = objcclass external;) and back then I tried to apply this to Object Pascal classes as well, but there where issues that made this functionality impossible.
So if there should be something, then it would have to follow the concept of the formal declarations like forward declarations, but what will NEVER be is that you can use the type without any kind of declaration (and obviously some situations will not work, like for example inheriting, because for that the full, non-formal type needs to be available, this will also not change).
Ryan J:
--- Quote from: PascalDragon on February 18, 2024, 02:22:22 pm ---
--- Quote from: Ryan J on February 18, 2024, 01:30:27 pm ---
--- Quote from: PascalDragon on February 18, 2024, 01:19:02 pm ---The language philosophy is “declare before use” and is one of the main principles of Pascal along with “separation of declaration and definition” and we uphold these, because they lead to clearer code.
--- End quote ---
To be clear I'm just talking about resolving types from different units which have circular dependancies, not allowing declaring types in any order. The problem can be fixed but moving all types into a single unit but this cripples what's nice about units.
--- End quote ---
For Objective Pascal Jonas had added the concept of formal declarations (TSomeType = objcclass external;) and back then I tried to apply this to Object Pascal classes as well, but there where issues that made this functionality impossible.
So if there should be something, then it would have to follow the concept of the formal declarations like forward declarations, but what will NEVER be is that you can use the type without any kind of declaration (and obviously some situations will not work, like for example inheriting, because for that the full, non-formal type needs to be available, this will also not change).
--- End quote ---
Oh yes I used Objective Pascal extensively and released a number of commercial apps with it (made the parser as you know I'm sure). I took the formal declarations for granted but what did they really do? Just tell the compiler to expect a resolution from another unit?
To be clear I'm talking about this scenario where you have two classes that reference each other but because units are nice and this isn't C we want to put them in their own units. Currently we can do this and have to make abstract classes which are unneeded if the compiler could figure this out.
I guess if you had a formal declaration it would be resolved when the another unit used both these units. It doesn't sound like a breaking change to the language or something intractable to solve.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit UnitA;interface type TMyClass = class function GetSomething: TData; end; implementation end. unit UnitB;interface type TData = class value: Pointer; function GetOwner: TMyClass; end; implementation end.
Curt Carpenter:
--- Quote from: PascalDragon on February 18, 2024, 01:19:02 pm ---...
The language philosophy is “declare before use” and is one of the main principles of Pascal along with “separation of declaration and definition” and we uphold these, because they lead to clearer code.
...
--- End quote ---
+1
marcov:
Objective * afaik has more a dispatch object model, and inheritance is not the only way to synthesise objects? That put less of a stress on order of declaration, but that doesn't pass onto Pascal classes, which are wholly declarative.
Navigation
[0] Message Index
[#] Next page
[*] Previous page