Recent

Author Topic: OOP structures in fpc and Lazarus  (Read 23909 times)

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: OOP structures in fpc and Lazarus
« Reply #30 on: November 12, 2021, 11:02:48 am »
Thaddy, maybe there is still some misunderstanding?

This was about class vars. The docu of NewInstance only talks about instances.

Code: Pascal  [Select][+][-]
  1. Type TFoo = class
  2.   class var bar: Integer;
  3. end;

Is bar initialized to zero on program startup or not?


Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: OOP structures in fpc and Lazarus
« Reply #31 on: November 12, 2021, 12:29:47 pm »
It is initialized to zero. There is no misunderstanding here.
It only CAN change behavior on overrides of NewInstance.

Anyway, the debugger will show you it is initialized.
« Last Edit: November 12, 2021, 12:32:43 pm by Thaddy »
Specialize a type, not a var.

jollytall

  • Sr. Member
  • ****
  • Posts: 306
Re: OOP structures in fpc and Lazarus
« Reply #32 on: November 14, 2021, 03:55:10 pm »
Thanks for the many useful comments and answers. I made a new version and uploaded it to github (as again, it was suggested).

Few key changes:
Added a history and usability overview, clarifying the strong preference towards class and record vs. object and advanced record.
Specified more what to use in classes and objects even when the compiler allows both.
Corrected many smaller mistakes, typos, etc.

It is now uploaded as an editable document, but still it has to be downloaded. Maybe github is still not the best (or I did not find how to make it online visible), it would be better a web page to use.

The link:https://github.com/zsoltszakaly/OOPstructuresinpascal/blob/main/structures%20in%20pascal.odt

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: OOP structures in fpc and Lazarus
« Reply #33 on: November 14, 2021, 04:36:24 pm »
Quote
TP objects are similar to records in many ways, but include basically everything that is needed for writing OO programs. It implemented methods, properties, inheritance, virtualization, constructors and destructors, i.e. practically everything that is needed for OOP.

Afaik TP didn't implement properties.

Quote
Later Embarcadero probably realized that the old object was not so bad after all,

IMHO that suggests a link that is simply not there.   The actual reasoning was copying from .NET to get similar generics, where structs carried operators as methods, so the specializing code could look in their definition for those operators, rather than scanning the global namespace for them. (where they might not even exist, e.g. if the record is type aliased)

« Last Edit: November 14, 2021, 04:42:23 pm by marcov »

jollytall

  • Sr. Member
  • ****
  • Posts: 306
Re: OOP structures in fpc and Lazarus
« Reply #34 on: November 14, 2021, 09:19:25 pm »
@marcov
Thanks for the clarifications.
Indeed TP had no properties as I also said it later in the document, but it remained incorrectly in the introduction. Will correct.
Also thanks for the reason on advanced record. Will also change that.

Blade

  • Full Member
  • ***
  • Posts: 177
Re: OOP structures in fpc and Lazarus
« Reply #35 on: November 14, 2021, 09:48:50 pm »
In regards to Turbo Pascal and Objects, I think it should be kept in mind that Turbo Pascal is freeware that is still used.  To include in some poorer countries, as a way to introduce Pascal.  This link at SourceForge is just one of many (https://sourceforge.net/projects/turbopascal-wdb/) where it can be downloaded.

I'm of the opinion that it is to the strategic advantage of Free Pascal/Lazarus to maintain portability and compatibility with Turbo Pascal (including with Objects), in order to be a viable alternative and "upgrade" path for those that happen to use or stumble across it.  Turbo Pascal was of such popularity at one time, that it still has significant recognition and public presence.

I would not disagree with anyone recommending Advanced Records or Classes over the use of Turbo Pascal style Objects, but I can see where it makes the transition easier for those that have a lot of Turbo Pascal code and projects, or have strongly established preferences for coding a certain way (like using Objects without Classes).
« Last Edit: November 23, 2021, 08:00:18 pm by Blade »

Blade

  • Full Member
  • ***
  • Posts: 177
Re: OOP structures in fpc and Lazarus
« Reply #36 on: November 23, 2021, 07:55:13 pm »
...various OOP structures, like advanced records, objects, classes...
P.S. It was written as.odt originally (55Kb), but it could not be attached, so I saved as .docx (47Kb).

Another place that might be great for your accumulated knowledge (and other advanced users), could be at Wikibooks for Pascal programming.  You can put in more information on OOP, in addition to link to your .odt/.pdf document.

https://en.wikibooks.org/wiki/Pascal_Programming
(Pascal Programming, Wikibooks)

jollytall

  • Sr. Member
  • ****
  • Posts: 306
Re: OOP structures in fpc and Lazarus
« Reply #37 on: November 24, 2021, 08:49:07 am »
Thanks.
It is already on GitHub (see 6 posts above) as it had been suggested before. I don't mind anyone putting it on wikibooks, or probably the best would be if someone put a link there, so any possible further changes are not forked.

Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: OOP structures in fpc and Lazarus
« Reply #38 on: November 24, 2021, 02:33:58 pm »
In regards to Turbo Pascal and Objects, I think it should be kept in mind that Turbo Pascal is freeware that is still used.  To include in some poorer countries, as a way to introduce Pascal.  This link at SourceForge is just one of many (https://sourceforge.net/projects/turbopascal-wdb/) where it can be downloaded.
No it is not. And the provided link is in violation of the original museum copyrights.
three versions of TurboPascal are still available from the museum at Embarcadero. (1.0, 3.0 and 5.5) but you should install Dosbox yourself and THEN install one of those versions to be legally compliant.
(btw: these versions work great on a Rasperry Pi with dosbox)
The re-packaging is not allowed. In that sense it is not freeware at all. It is free to use ware.And you need a registration/account to download it legally. Which is free... and the whole process is a doddle so I don't get it why that illegal distribution is on sourceforce. Only the museum will give you truly legal use of the software.

Again: you will need an EDN registration first, otherwise the - legal - links that can be found won't work, since you can not login.
« Last Edit: November 24, 2021, 02:48:21 pm by Thaddy »
Specialize a type, not a var.

Blade

  • Full Member
  • ***
  • Posts: 177
Re: OOP structures in fpc and Lazarus
« Reply #39 on: November 24, 2021, 05:36:17 pm »
No it is not. And the provided link is in violation of the original museum copyrights...
...three versions of TurboPascal are still available from the museum at Embarcadero. (1.0, 3.0 and 5.5) but you should install Dosbox yourself and THEN install one of those versions to be legally compliant.
...The re-packaging is not allowed. In that sense it is not freeware at all. It is free to use ware...

I'm not going to disagree with your point, as it might be technically correct.  However, it is merely a technicality in terms of usage or getting access to Turbo Pascal.  There are plenty of places that either allow download by 3rd parties other than Embarcadero, so the person doesn't have to sign up with them, or are providing downloads of packages that include both Dosbox and Turbo Pascal.  Even if the person doesn't want to use 3rd parties and makes sure they are in legal compliance, it's of a minor inconvenience to install Dosbox before downloading Turbo Pascal.  Usually such people would be highly enthusiastic and/or nostalgic types that are going to be sure to get it and play with it. 

If the SourceForge downloads per week are to be believed, it is a significant number of downloads, and that's just one of many sources.  It can be indicative of there still being interest in Turbo Pascal (Pascal in general), thus arguably, Free Pascal should position itself appropriately and as a "next step" to enthusiasts, hobbyist, independents, small businesses...

In regards to Objects/Records/Advanced Records versus Classes, there is also a kind of philosophical angle at work too.  Various people are going to prefer, feel more comfortable with, or choose the alternatives and not use Classes for their projects or particular program.  There is nothing wrong with that, especially if we are talking smaller programs and tasks, but even if they simply don't want to use such directly or minimize such usage.  People have/do/can make plenty of interesting and useful programs with Turbo Pascal style Objects. As long as they are useful and beneficial to them, hard to argue against their choices.  We also might want to keep in mind that there are some other popular languages that don't use Classes or can use Objects without Classes, such as Go, JavaScript, Lua, etc...  Free Pascal/Lazarus can be "philosophically" attractive to such users too, where they have more flexibility in the paradigm they want to use.

Part of what is great about Free Pascal/Lazarus is the features, options, and choices that it provides.
« Last Edit: November 24, 2021, 06:10:33 pm by Blade »

ArtLogi

  • Full Member
  • ***
  • Posts: 184
Re: OOP structures in fpc and Lazarus
« Reply #40 on: November 30, 2021, 09:41:13 am »
As has been pointed out, objects are basically deprecated. Some folks still use them, but if I was learning I would pass over them.
As a beginner comment. If 'Objects' are depricated, why is that most LCL more complex data structures (what ever they are called) begin with T and are inherited from TObject? How I can stop using those deprecated objects?  :o
While Record is a drawer and method is a clerk, when both are combined to same space it forms an concept of office, which is alias for a great suffering.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: OOP structures in fpc and Lazarus
« Reply #41 on: November 30, 2021, 10:19:00 am »
As has been pointed out, objects are basically deprecated. Some folks still use them, but if I was learning I would pass over them.
As a beginner comment. If 'Objects' are depricated, why is that most LCL more complex data structures (what ever they are called) begin with T and are inherited from TObject? How I can stop using those deprecated objects?  :o

Have you read the document that this thread is discussing? Have you read the FPC etc. documentation?

Despite its name TObject isn't an object (in the sense of the "objects" introduced by Turbo Pascal and later documented).

It's the ultimate superclass of anything declared as a class, where a class can be instantiated into something which is commonly called "an object".

The terminology is unfortunate. Get used to it.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: OOP structures in fpc and Lazarus
« Reply #42 on: November 30, 2021, 10:29:16 am »
As has been pointed out, objects are basically deprecated. Some folks still use them, but if I was learning I would pass over them.
As a beginner comment. If 'Objects' are depricated, why is that most LCL more complex data structures (what ever they are called) begin with T and are inherited from TObject? How I can stop using those deprecated objects?  :o
There is major confusion here, partly owing to the inherited and confusing use of the term "object" which can and does mean several things depending on context.

TP objects:
Code: Pascal  [Select][+][-]
  1. TTurboPascalObject = object...end;
are not deprecated in the FP compiler, only in the Delphi compiler.

Classes:
Code: Pascal  [Select][+][-]
  1. TpostTurboPascalClass = class(TObject)...end;
confusingly all descend from "TObject" but this is not a TurboPascal object, but a more complex and more capable construct. The naming was defined by Borland, not by FPC which uses it only to be compatible. However it is a source of confusion for newcomers.
« Last Edit: November 30, 2021, 10:33:08 am by howardpc »

jollytall

  • Sr. Member
  • ****
  • Posts: 306
Re: OOP structures in fpc and Lazarus
« Reply #43 on: November 30, 2021, 10:34:25 am »
As a beginner comment. If 'Objects' are depricated, why is that most LCL more complex data structures (what ever they are called) begin with T and are inherited from TObject? How I can stop using those deprecated objects?  :o
Please check the document I wrote. This was actually one of the first pieces of confusion I had years ago, (followed by many others,) that caused me to start writing it.

ArtLogi

  • Full Member
  • ***
  • Posts: 184
Re: OOP structures in fpc and Lazarus
« Reply #44 on: November 30, 2021, 12:58:56 pm »
Thank you jollytall, I did read your article first public version, it was really nice read up for an amateur like me.

For the angry answer, yes I did actually verify the class vs. object in TObject declaration, but that would not have been any help to not to post beginners first thoughts.

PS. Isn't type SET also a primitive object datatype, kind of list-object as lack of better description.  :-\
While Record is a drawer and method is a clerk, when both are combined to same space it forms an concept of office, which is alias for a great suffering.

 

TinyPortal © 2005-2018