Jump to content
dummzeuch

Some more fun with ChatGPT and Delphi

Recommended Posts

I just spent some time testing ChatGPTs ability to "understand" and explain Delphi source code. The results were actually quite good.

 

I asked ChatGPT "what’s wrong with the following Delphi code?"

function IsoStringToDateTime(const ISODateTime: string): TDateTime;
const
  ISOShortLen = 19;
  ISOFullLen = 23;
var
  y, m, d, h, n, s, z: Word;
begin
  // ISODateTime should be in one of these formats:
  // YYYY-MM-DDTHH:NN:SS, YYYY-MM-DD HH:NN:SS
  // YYYY-MM-DDTHH:NN:SS.ZZZ, YYYY-MM-DD HH:NN:SS.ZZZ
  if (Length(ISODateTime) <> ISOShortLen) and (Length(ISODateTime) <> ISOFullLen) then
    raise EConvertError.Create('Invalid ISO date time string: ' + ISODateTime);
  y := SysUtils.StrToInt(Copy(ISODateTime,  1, 4));
  m := SysUtils.StrToInt(Copy(ISODateTime,  6, 2));
  d := SysUtils.StrToInt(Copy(ISODateTime,  9, 2));
  h := SysUtils.StrToInt(Copy(ISODateTime, 12, 2));
  n := SysUtils.StrToInt(Copy(ISODateTime, 15, 2));
  s := SysUtils.StrToInt(Copy(ISODateTime, 18, 2));
  z := StrToIntDef(Copy(ISODateTime, 21, 3),  0); // Optional
  Result := EncodeDate(y, m, d) + EncodeTime(h, n, s, z);
end;

 

and also "What does the following Delphi function do?"

function FileSizeToHumanReadableString(_FileSize: Int64): string;
begin
  if _FileSize > 5 * OneExbiByte then
    Result := Format(_('%.2f EiB'), [_FileSize / OneExbiByte])
  else if _FileSize > 5 * OnePebiByte then
    Result := Format(_('%.2f PiB'), [_FileSize / OnePebiByte])
  else if _FileSize > 5 * OneTebiByte then
    Result := Format(_('%.2f TiB'), [_FileSize / OneTebiByte])
  else if _FileSize > 5 * OneGibiByte then
    Result := Format(_('%.2f GiB'), [_FileSize / OneGibiByte])
  else if _FileSize > 5 * OneMebiByte then
    Result := Format(_('%.2f MiB'), [_FileSize / OneMebiByte])
  else if _FileSize > 5 * OneKibiByte then
    Result := Format(_('%.2f KiB'), [_FileSize / OneKibiByte])
  else
    Result := Format(_('%d Bytes'), [_FileSize]);
end;

 

The answers will surprise you. And these were the shocking answers.

 

The answers were actually quite interesting.

Edited by dummzeuch
  • Like 3
  • Thanks 2

Share this post


Link to post
37 minutes ago, Dave Nottage said:

Check the links in his post

I think you're assuming that I find the answers interesting, which I do not.

I'm asking why he thinks they're "quite interesting".

 

From a socio-psychological viewpoint, I think people's view of ChatGPT is "quite interesting". Beyond that, from what I've seen so far, the only practical use for ChatGPT is to waste everybody's time. YMMV

937979619_oldmanyellsatcloud.thumb.jpg.c888d62a5456aaa618666db5821c52d3.jpg

Edited by Anders Melander
  • Like 3

Share this post


Link to post
4 minutes ago, Anders Melander said:

I think you're assuming that I find the answers interesting, which I do not.

I never assumed anything like that.

4 minutes ago, Anders Melander said:

I'm asking why he thinks they're "quite interesting".

What is missing from his post that raises that question?

 

Share this post


Link to post
3 minutes ago, Dave Nottage said:

What is missing from his post that raises that question?

Um... An explanation of why it's interesting for example.

 

As far as I can tell it performed just as one could expect. Is that interesting?

Share this post


Link to post
36 minutes ago, Anders Melander said:

Um... An explanation of why it's interesting for example.

 

As far as I can tell it performed just as one could expect. Is that interesting?

I didn't expect it to perform that well, in particular the descriptions it gave for what those functions do. I found that interesting.

 

These were simple tests where I knew the correct answers. It might be helpful in cases where I don't know the answers. Our possibly not. The code I'm usually dealing with is much more complex than a simple function. But you never know.

 

Regardless of whether it will ever be helpful, I had some fun.

Edited by dummzeuch

Share this post


Link to post
1 hour ago, dummzeuch said:

I had some fun.

Sure; It's a nice party trick. But it gets old.

 

1 hour ago, dummzeuch said:

These were simple tests where I knew the correct answers.

Exactly. Most of the examples I have seen so far of ChatGPT magically writing code usually involves the operator coaching it through iterations of incorrect answers toward the known correct answer.

 

ChatGPT's linguistic abilities are very impressive. The rest, not so much.

Share this post


Link to post
7 hours ago, Anders Melander said:

Most of the examples I have seen so far of ChatGPT magically writing code usually involves the operator coaching it through iterations of incorrect answers toward the known correct answer.

I wasn't aware that I did that. Did I?

Share this post


Link to post

Hmm, probably finding bugs in code would be very useful task for this tool.

Another boring task that I think of is generating test cases for unit tests - could someone check this?

Edited by Fr0sT.Brutal

Share this post


Link to post

Having an AI that can point out bugs or suggest improvements in MY code, is far more interesting than having purely AI generated code, IMO.

 

On the other hand, I use the ISO8601 methods in System.DateUtils 😛

Share this post


Link to post

This is the modern way of pair-programming, where also the human pair-partner can say something complete stupid from time to time.
I see not much difference, only that ChatGPT has a lot more knowledge than a junior-pair-partner might have.

Yaaaaa, its ONLY a text-processor ( byte by byte ) ... who cares ?

Edited by Rollo62

Share this post


Link to post
2 hours ago, Lars Fosdal said:

Having an AI that can point out bugs or suggest improvements in MY code, is far more interesting than having purely AI generated code, IMO.

 

On the other hand, I use the ISO8601 methods in System.DateUtils 😛

You could aks ChagGPT to look for bugs in these. 😉 

Share this post


Link to post

image.png.3439ed2de773aea7f886353e495c2071.png

 

:classic_unsure: ...here we are now! Not personal ...for the current and the next generation. :classic_blink:

Edited by haentschman
  • Like 1

Share this post


Link to post
7 minutes ago, haentschman said:

image.png.3439ed2de773aea7f886353e495c2071.png

I think Albert was slightly wrong ( only in that case ... and with his cosmological constant ).
We have already a world full of idiots, but unfortunately the technology has not yet surpassed our human interactions yet, to help us out of desaster.  Maybe that is the whole problem :classic_biggrin:

  • Like 2

Share this post


Link to post

Regarding

IsoStringToDateTime

the optimization/checks that ChatGPT introduced are not sufficient:

  if (d < 1) or (d > DaysInAMonth(y, m)) then
    raise EConvertError.Create('Invalid day of the month: ' + IntToStr(d));
  if (m < 1) or (m > 12) then
    raise EConvertError.Create('Invalid month of the year: ' + IntToStr(m));

This checks the day using the month (m) which could have an invalid value (the check for valid months comes later). So it didn't take the ordering for the checks into account.

 
  • Like 2

Share this post


Link to post
On 1/29/2023 at 3:39 PM, dummzeuch said:

But you never know.

That's the problem. And ChaptGPT doesn't know what it does not know, which makes it even worse. ChatGPT is very confident in its answers even when it is egregiously wrong. But even worse is when it is confidently wrong in a subtle way. It's fun, perhaps interesting, but not useful. We already have college students surprised when they turn in work written by ChatGPT and get failing grades. These students (and people like them) are what scare me. They trust ChatGPT when they should not.

  • Like 5

Share this post


Link to post

The most important part is, that ChatGPT was trained with data from the past. There is no continuous aggregation of knowledge or something.

So all answers, how accurate or fascinating they may be, are based on "old" data.

Edited by baka0815
  • Like 1

Share this post


Link to post
11 minutes ago, baka0815 said:

So all answers, how accurate or fascinating they may be, are based on "old" data.

I'm not sure how would it affect the "write a poem in norwegian" command

Share this post


Link to post

It probably wouldn't affect a command like that (much), but we're talking about programming here. And there are new design patterns, language features and so on.

A command like "write a poem in current teens language" might not work.

 

Share this post


Link to post
30 minutes ago, baka0815 said:

The most important part is, that ChatGPT was trained with data from the past.

Sure: Everything was better in the past :classic_biggrin:

  • Haha 3

Share this post


Link to post

It `s Magic. Before our eyes, large artificial neural networks are becoming more and more intelligent.

  • Like 1

Share this post


Link to post
1 hour ago, Attila Kovacs said:

I'm not sure how would it affect the "write a poem in norwegian" command

It would probably use "old norse".

  • Haha 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×