Lazarus

Free Pascal => General => Topic started by: x2nie on April 24, 2018, 11:22:24 am

Title: Compile Photoshop Pascal Code
Post by: x2nie on April 24, 2018, 11:22:24 am

Hi guys, you know Adobe Photoshop source code is available to download and was written in Pascal programming language.
http://forum.lazarus.freepascal.org/index.php/topic,19922.0.html


It said that it is released to public for learning purpose.


Sadly I didn't understand it because it is not written in OOP (which I expected to be).
Perhaps the dialect is too old, and I assumed that nowadays Pascal Language is very different.
--------


So, for learning purpose I have few questions:


1. What is advantage of using "Object" rather than "Class"
2. What is difference between "Object" and "TObject" ?
3. Was there OOP implementation in the day Photoshop 1.0 being written ?
3.b) if it was, why they were using Object instead of Class ?
4. How can we compile the source code (using cross-compile or whatever) ?
5. What the compiler they use to build/compile ?
6. Am I right: I think the fpc is not available yet in that day?


I am very curios because all information/comment in internet of Photoshop 1.xx source code is about general programming, I didn't found yet in specific Pascal Programming Languange, which is it was written in.


thanks you :-*
Title: Re: Compile Photoshop Pascal Code
Post by: Handoko on April 24, 2018, 12:04:01 pm
I ever heard that using object is faster than class because object allocate memory on the stack while class is on the heap.

TObject is the base class of all classes. Read more: http://wiki.freepascal.org/TObject (http://wiki.freepascal.org/TObject)

Free Pascal first released on 1997, Adobe Photoshop in 1990. Not sure what compiler they used. I guess Delphi/TP/TPWIn, because those were very famous in the old time.
Title: Re: Compile Photoshop Pascal Code
Post by: RayoGlauco on April 24, 2018, 12:39:11 pm
I found a web page that explains how to compile the old version of Photoshop. It says:
Quote
If you are going to build Photoshop from the distributed files, you need a Macintosh Object Pascal compiler, its associated libraries, and the appropriate version of the MacApp class library.

http://basalgangster.macgui.com/RetroMacComputing/The_Long_View/Entries/2013/3/30_Building_Photoshop.html (http://basalgangster.macgui.com/RetroMacComputing/The_Long_View/Entries/2013/3/30_Building_Photoshop.html)
Title: Re: Compile Photoshop Pascal Code
Post by: Thaddy on April 24, 2018, 12:43:59 pm
I found a web page that explains how to compile the old Photoshop version. It says:
Quote
If you are going to build Photoshop from the distributed files, you need a Macintosh Object Pascal compiler, its associated libraries, and the appropriate version of the MacApp class library.

http://basalgangster.macgui.com/RetroMacComputing/The_Long_View/Entries/2013/3/30_Building_Photoshop.html (http://basalgangster.macgui.com/RetroMacComputing/The_Long_View/Entries/2013/3/30_Building_Photoshop.html)
Indeed. Note FPC supports -Mmacpas but it may be that not all dependencies can be resolved against anything other than a Macintosh OS. As I understand the first Windows version was written in mspascal/quickpascal which is TP compatible (including bugs!). That would be 16 bit Windows.....
I blew up my Macintosh more than 10 years ago..... Can't test.
Title: Re: Compile Photoshop Pascal Code
Post by: tr_escape on April 24, 2018, 01:42:38 pm
I looked up some files of project it has got assembly parts (example: USeparation.a).

It is not easy to convert...


Ok they only compiled parts :) but it isn't easy to convert
Title: Re: Compile Photoshop Pascal Code
Post by: marcov on April 24, 2018, 02:19:13 pm
Note also that in old Apple Object Pascal (and mode macpas), the object()  syntax is reference based like Delphi class, and thus NOT equal to Turbo Pascal static object() syntax.
Title: Re: Compile Photoshop Pascal Code
Post by: Leledumbo on April 24, 2018, 04:29:51 pm
1. What is advantage of using "Object" rather than "Class"
I'm answering from TP/FPC POV, not MacPas. Object is allocated on the stack, class is always on the heap. Object will be freed automatically when the function goes out of scope, class requires either garbage collection or explicit deallocation.
2. What is difference between "Object" and "TObject" ?
Object is a reserved word, it's mean to signify that a type is... well... an object. TObject is the root class (or object) of all other defined classes / objects.
3. Was there OOP implementation in the day Photoshop 1.0 being written ?
No idea, but the first Object Pascal proposal is from 1982, while Photoshop 1.0 was born in 1990. Note that the proposal was never finalized, so it's unknown whether there's a compiler implemeting it that day.
3.b) if it was, why they were using Object instead of Class ?
No idea again, you might want to just read the proposal: http://www.pascal-central.com/OOE-stds.html
4. How can we compile the source code (using cross-compile or whatever) ?
Answered above, in short: it's hard to find the dependencies.
5. What the compiler they use to build/compile ?
MacPas compiler of that day for sure.
6. Am I right: I think the fpc is not available yet in that day?
No, FPC was first started in 1992, when Borland said there will be no TP 8. First public release I believe it was around 1998. Florian should be able to confirm, my first encounter with FPC was at version 1.0.2 around 2000.
Title: Re: Compile Photoshop Pascal Code
Post by: x2nie on April 25, 2018, 07:40:18 am

Thanks you every body. Your answers enlighten me so much.

Read more: http://wiki.freepascal.org/TObject
then this too: http://wiki.freepascal.org/Object


1. What is advantage of using "Object" rather than "Class"
I'm answering from TP/FPC POV, not MacPas. Object is allocated on the stack, class is always on the heap. Object will be freed automatically when the function goes out of scope, class requires either garbage collection or explicit deallocation.
5. What the compiler they use to build/compile ?
MacPas compiler of that day for sure.
MacPas, I found nothing about it except that in fpc there is compiler-compatible-mod {$mode macpas}.
http://wiki.freepascal.org/Mode_MacPas
There is said: "Mode MacPas tries to be compatible with the Pascal dialects commonly used on Macintosh, that is THINK Pascal, Metrowerks Pascal and MPW Pascal. For tips on porting from traditional Mac Pascal compiler to Free Pascal, see Porting from Mac Pascal"
So, I think youre talking about any of compiler for mac. Never mind.


Thanks you every body, its enough and is satisfied my curiosity. In fact, the answers are beyond it  :o 8-)
Title: Re: Compile Photoshop Pascal Code
Post by: Thaddy on April 25, 2018, 12:03:45 pm
AFAIk macpas mode ==~ Think pascal. Not the other ones.
Title: Re: Compile Photoshop Pascal Code
Post by: VTwin on June 24, 2018, 07:47:35 pm
1. What is advantage of using "Object" rather than "Class"
3.b) if it was, why they were using Object instead of Class ?

I believe the use of Object instead of Class reflects the style of that time. Objects can be declared with fields and methods, similar to Classes, but have no constructors or destructors, and are not allocated. They were phased out (deprecated).

Code: Pascal  [Select][+][-]
  1. type
  2.   TAnObject = object (TAnAncestorObject)
  3.     AName: string
  4.     function AFunction: integer;
  5.   end;
  6.  

From Delphi docs:

Quote
Object types are supported for backward compatibility only. Their use is not recommended.

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Classes_and_Objects_(Delphi)
[Link is not working, copy and Google if interested.]

Interestingly we now have "advanced" records, which are very much like objects, but without inheritance.

https://forum.lazarus.freepascal.org/index.php?topic=30686.0

Happy coding,
VTwin
Title: Re: Compile Photoshop Pascal Code
Post by: ASerge on June 24, 2018, 08:03:44 pm
Objects can be declared with fields and methods, similar to Classes, but have no constructors or destructors, and are not allocated.
Сarried away by belittling the capabilities of the object type? They can have a constructor and a destructor.
Title: Re: Compile Photoshop Pascal Code
Post by: marcov on June 24, 2018, 08:10:32 pm
From Delphi docs:

Useless since Mac Pascal "object" is not necessary to object in other modes (including TP/Delphi), as the following program demonstrates:

Code: Pascal  [Select][+][-]
  1.  
  2. {$mode macpas}
  3.  
  4. type TSomething = object
  5.                     l1,l2,l3: integer;
  6.  
  7.                        end;
  8.  
  9. var x : TSomething;
  10.  
  11. begin
  12.  writeln(sizeof(x));   // In mode macpas prints 4 on 32-bits systems, a reference!  Change to mode Delphi and see the value change to 12
  13. end.
  14.  
Title: Re: Compile Photoshop Pascal Code
Post by: VTwin on June 24, 2018, 08:17:51 pm
Objects can be declared with fields and methods, similar to Classes, but have no constructors or destructors, and are not allocated.
Сarried away by belittling the capabilities of the object type? They can have a constructor and a destructor.

Sorry, I did not mean to belittle them. I was disappointed to learn that Delphi "broke" them. I use advanced records a lot, and would prefer to use objects. I was using objects, but moved to advanced records. Thank you for pointing out my error, perhaps I should start using them again. Do many here folks still use objects?
Title: Re: Compile Photoshop Pascal Code
Post by: VTwin on June 24, 2018, 08:23:43 pm
Useless since Mac Pascal "object" is not necessary to object in other modes (including TP/Delphi), as the following program demonstrates:

Interesting. It seems that what they are depends on the mode. That makes me nervous. Should I not use them then?
Title: Re: Compile Photoshop Pascal Code
Post by: VTwin on June 24, 2018, 08:52:00 pm
To clarify my question, I do not like the fact that advanced records do not have constructors. This makes me write code like this:

Code: Pascal  [Select][+][-]
  1. type
  2.   TMyRecord = record
  3.     MaxAllowed: integer;
  4.     MinAllowed: integer;
  5.     procedure Init;
  6.   end;
  7.  
  8. procedure TMyRecord.Init;
  9. begin
  10.   MaxAllowed := 100;
  11.   MinAllowed := 0;
  12. end
  13.  
  14. var
  15.   r : TMyRecord;
  16. begin
  17.   r.Init;
  18. end.
  19.  
  20.  

I would prefer to use a constructor. Having learned that Delphi "broke" them, I have stayed away from objects. I am curious as to what other folks do.
Title: Re: Compile Photoshop Pascal Code
Post by: ASerge on June 24, 2018, 09:30:04 pm
Compare advanced records and objects:
1. Advanced records support type helper (static polymorphism).
2. Objects support virtual function (dynamic polymorphism) and inheritance (static polymorphism).
All other properties are the same.
Title: Re: Compile Photoshop Pascal Code
Post by: Nitorami on June 24, 2018, 09:51:21 pm
Why would you need a constructor ? It is only required to build the VMT which is necessary for inheritance & virtual methods which advanced records don't support.

Objects are really like Classes, except they are static and need not be allocated, hence it is not necessary to "create" them. Only if you are using inheritance, then you need a constructor. That is my understanding. I don't know about type helpers.

I had started my own program based on objects, but came to a point where things went wrong. I don't know whether "Delphi broke objects", but have the feeling the developers neglected them, once Classes had been implemented. So I changed to Classes, but still use simple objects to capsule simple data and methods. But I don't use constructors / inheritance on objects anymore, neither properties... I remember they seemed to be buggy.
The advantage of objects is that access to their fields may be a little bit faster than for Classes, although that only matters in tight loops.
Title: Re: Compile Photoshop Pascal Code
Post by: VTwin on June 24, 2018, 11:34:58 pm
Thanks guys, I appreciate the responses.

A few years ago I started writing a vector library using TVector and TMatrix objects (I write scientific software at a university). At some point I encountered some unexpected behavior. I inquired here, and learned that objects were deprecated, or at least not maintained. It sounds like you (Nitorami)  may have encountered the same issue. Despite the error in my earlier post, I was using object constructors, which I forgot. (I have long since rewritten the library using dynamic arrays and operator overloading).

I do use advanced records extensively, often to set and get options for a complex procedure which are logically grouped together. These are typically set in a dialog box, and then saved to a preferences dictionary in memory, which can be written to a file and reloaded when the program is restarted. Each such record must have default values, which I set in an Init method. It is not such a big deal, but it would be nice to have a constructor to do that automatically. 

So at least one other person has had issues, at least with object constructors or inheritance. I suppose I could use objects and not use constructors or inheritance, but advanced records seem to work well.

TinyPortal © 2005-2018