Recent

Author Topic: Question about A.I  (Read 2496 times)

440bx

  • Hero Member
  • *****
  • Posts: 5805
Question about A.I
« on: September 04, 2025, 06:39:50 pm »
Hello,

This question is directed at folks who use A.I to a fair extent and have gotten reasonably good at knowing how to get reasonably good results out of it.

As most, if not all, Pascal programmers know, it is rather common to have to port/translate C/C++ code to Pascal.   Most often for library bindings but, also for examples of how to do one thing or another, e.g, use one or more Windows APIs.

My question is: do you believe A.I could do a reasonably decent job, IOW, not necessarily perfect but close, in translating C examples to Pascal ?   To be clearer about what I have in mind, could A.I translate the example programs found in Petzold's Programming Windows book to FPC Pascal well enough that it wouldn't take more than a few minutes (say 10 to 15) to make the example work as intended ?

Thank you for your input.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18300
  • Here stood a man who saw the Elbe and jumped it.
Re: Question about A.I
« Reply #1 on: September 04, 2025, 06:43:08 pm »
DeepSeek and Copilot do that instantly (Petzold)  , when the question is properly phrased.
Most AI users are to stupid to ask questions in a proper way.
« Last Edit: September 04, 2025, 06:45:19 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Question about A.I
« Reply #2 on: September 04, 2025, 06:53:01 pm »
Ok... now I have a question for you....

if I posted one of those example programs from Petzold's book, could you phrase the request properly to obtain a good port to FPC Pascal ?

PS: I doubt that posting one program out of possibly over a hundred is a copyright infringement, just what is considered a quote which is perfectly acceptable.


FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18300
  • Here stood a man who saw the Elbe and jumped it.
Re: Question about A.I
« Reply #3 on: September 04, 2025, 07:53:33 pm »
If it is the C book, without hesitance, yes... (I don't need AI for that)
I have the books, just give me edition and chapter.

Btw this icon of programming instruction has passed away recently.
And he was pretty decent in Pascal too...

May he rest softly.
« Last Edit: September 04, 2025, 08:00:07 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Question about A.I
« Reply #4 on: September 04, 2025, 08:19:24 pm »
If it is the C book, without hesitance, yes... (I don't need AI for that)
I have the books, just give me edition and chapter.

Btw this icon of programming instruction has passed away recently.
And he was pretty decent in Pascal too...

May he rest softly.
Yes, I don't need A.I either to port those examples but, the whole reason to use A.I to port them is to save myself some of that boring work.  Let A.I do that mindless boring stuff.

have whatever A.I program you are comfortable with port FONTOUT1.C (page 941, Figure 17-14), it would be nice if the thing managed to port the other three (3) examples that follow, namely FONTOUT2.C, FONTFILL.C and FONTCLIP.C

Those are very basic examples but, it would be great to have some tool do an "almost perfect" translation.  It would save time.

Thank you Thaddy.


ETA:

I'm referring to the 5th edition of the book Programming Windows.
« Last Edit: September 04, 2025, 08:21:20 pm by 440bx »
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18300
  • Here stood a man who saw the Elbe and jumped it.
Re: Question about A.I
« Reply #5 on: September 04, 2025, 08:48:02 pm »
I am sure he doesn't mind - he never did - any more but of course I am prepared to violate some copyright infringements in this case..
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

creaothceann

  • Full Member
  • ***
  • Posts: 195
Re: Question about A.I
« Reply #6 on: September 05, 2025, 08:08:47 am »
could A.I translate the example programs found in Petzold's Programming Windows book to FPC Pascal well enough that it wouldn't take more than a few minutes (say 10 to 15) to make the example work as intended?

When testing different programs you should probably not use a chat AI.
And don't start an argument, I am right.

Thaddy

  • Hero Member
  • *****
  • Posts: 18300
  • Here stood a man who saw the Elbe and jumped it.
Re: Question about A.I
« Reply #7 on: September 05, 2025, 11:54:07 am »
Quote
have whatever A.I program you are comfortable with port FONTOUT1.C (page 941, Figure 17-14), it would be nice if the thing managed to port the other three (3) examples that follow, namely FONTOUT2.C, FONTFILL.C and FONTCLIP.C
Here you go. Some of it. No AI necessary. Pity I already did this once (1998ísh) but that version got lost in time.

Now I will check if AI can come close.... Consider this the hand-crafted reference.

First result:
Deepseek failed three times, but comes very close with slight editing. Made major error in font size and could not work with ezfont. Also forgot that pascal is case sensitive and forgot to get the correct types out of the windows unit.

Copilot fared much better, but again forgot case insensitivity. To be fair I only needed renaming hfont, hdc etc. Copilot also used ezfont when provided. It came very close to my reference implementation.
« Last Edit: September 05, 2025, 01:55:49 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Question about A.I
« Reply #8 on: September 05, 2025, 01:39:54 pm »
Thaddy thank you very much.  I greatly appreciate your efforts.  It really is very nice.

Now, don't get me wrong.  The reason I asked the question about A.I is because I wanted to find out if ports of this kind could be done by some A.I facility requiring a _minimal_ amount of human time/work for "corrections".

I don't know how much time you spent on this but, I'm guessing it's probably more than 10 minutes per example. 

What I have in the back of my mind is, there are a gazillion examples MS makes available in various place and quite a few of them are very simple but, the time to port that code adds up quickly.  I was hoping A.I could do 98% of the grunt work and just leave a programmer with a simple "checking it's done right" pass over it.

Those Petzold programs are in the ballbark of the complexity level of many samples offered by MS.  That's why I selected them.

Your comments are welcome.

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18300
  • Here stood a man who saw the Elbe and jumped it.
Re: Question about A.I
« Reply #9 on: September 05, 2025, 01:58:42 pm »
The manual translations - all of them - costed about one hour (they are very similar). The demo app 20 minutes.
Corrections on the AI output and "discussion" also costed about an hour, but that was just on fontfill...So both AI models were definitely not a time saver.

That said, I have also encountered cases where AI definitely saved me a lot of time.

Note the petzold code is public domain.
The one from CoPilot needed just three renames and a {$mode objfpc}:
Code: Pascal  [Select][+][-]
  1. unit cpfontfill;{renamed}
  2. {$mode objfpc added}
  3. interface
  4. uses windows,ezfont;
  5.  
  6. procedure PaintRoutine(hwnd: THandle {renamed}; dc: HDC {renamed}; cxArea, cyArea: Integer);
  7.  
  8. implementation
  9.  
  10. procedure PaintRoutine(hwnd: THandle {renamed}; dc: HDC {renamed}; cxArea, cyArea: Integer);
  11. const
  12.   szString: PChar = 'Filling';
  13. var
  14.   Font: HFONT{renamed};
  15.   size: TSize;
  16. begin
  17.   Font := EzCreateFont(dc, PChar('Times New Roman'), 1440, 0, 0, True);
  18.   SelectObject(dc, Font);
  19.   SetBkMode(dc, TRANSPARENT);
  20.  
  21.   GetTextExtentPoint32(dc, szString, Length(szString), size);
  22.  
  23.   BeginPath(dc);
  24.   TextOut(dc, (cxArea - size.cx) div 2, (cyArea - size.cy) div 2, szString, Length(szString));
  25.   EndPath(dc);
  26.  
  27.   SelectObject(dc, CreateHatchBrush(HS_DIAGCROSS, RGB(255, 0, 0)));
  28.   SetBkColor(dc, RGB(0, 0, 255));
  29.   SetBkMode(dc, OPAQUE);
  30.  
  31.   StrokeAndFillPath(dc);
  32.  
  33.   DeleteObject(SelectObject(dc, GetStockObject(WHITE_BRUSH)));
  34.   SelectObject(dc, GetStockObject(SYSTEM_FONT));
  35.   DeleteObject(Font);
  36. end;
  37. end.

As you can see that is very, very close to my manual reference implementation.
You can simply plug-in the CoPilot code in my demo app for proof of correctness.
The DeepSeek code still needs more work. Still "discussing"

The reason I did the manual translations first is that should be a good benchmark and it is easy stuff.
Btw: Petzold wrote a good deal of the ms examples proper.
« Last Edit: September 05, 2025, 02:48:46 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Question about A.I
« Reply #10 on: September 05, 2025, 02:58:04 pm »
Yes, that code from Copilot looks pretty good.

I have another question, I see the code is structured to "fit" in the Lazarus framework, IOW, it is not the standard Windows message loop and message procedure.   

Did you have to tell it to do it  that way or did it choose to do it that way all by itself ?

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Question about A.I
« Reply #11 on: September 05, 2025, 03:35:48 pm »
Note the petzold code is public domain.
That's good to know.  Where did you get that information ?  I'd like the source because, I might need to refer to it in the future. 

Thanks.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18300
  • Here stood a man who saw the Elbe and jumped it.
Re: Question about A.I
« Reply #12 on: September 05, 2025, 04:31:12 pm »
I have another question, I see the code is structured to "fit" in the Lazarus framework, IOW, it is not the standard Windows message loop and message procedure.   
That is my own work (could have done a message loop+main). The C translations, however, are straight translations. I just put them in units, not programs.
The demo program makes such C translations a bit more accessible to Lazarus users. I decided that because of such a messageloop/main would be confusing to people without sufficient background in low-level Windows API programming.
And for people like you it is a fill-in exercise, not really programming.
« Last Edit: September 05, 2025, 04:38:30 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Question about A.I
« Reply #13 on: September 05, 2025, 06:25:11 pm »
Thank you Thaddy.

Got a reference for Petzold's code now being in the public domain ?
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18300
  • Here stood a man who saw the Elbe and jumped it.
Re: Question about A.I
« Reply #14 on: September 05, 2025, 07:35:18 pm »
Thank you Thaddy.

Got a reference for Petzold's code now being in the public domain ?

I have to double check it, but it is from a usually reliable source.
Also, https://archive.org/ has the sources and these people are reasonably careful.
« Last Edit: September 05, 2025, 07:40:10 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018