Saturday, January 17, 2026

Delphi and AI[10]: Coding GpTimestamp with Claude Code

A month ago I wrote a nice little unit that simplifies working with timestamps received from different sources - GpTimestamp - with help from Claude Code. Actually, to be fair - I took a backseat, set the goals, provided some info, and let Claude do all the work. I already wrote a post about GpTimestamp, but I said nothing about the coding experience. Let's fix that!

The Problem

I wanted to write GpTimestamp for a long time. While I usually know in advance what code I need, in this case I was quite unsure. I knew the code should handle some specific cases but was really unsure about the approach and the scope of the API. Because I didn't desperately need the new unit, I solved that in the simplest manner - I didn't even start doing the work.

Enter Claude Code

Then came the day when I wanted to test Claude Code, and this seemed like a perfect problem. I decided to approach it as a pair programming session where I would be the navigator, providing ideas, and Claude would do the driving (coding). In this case, this was a perfect solution for me. I could focus on ideas and Claude would do the dirty work while I was doing something else. Perfect - assuming Claude manages to do its part. (Spoilers: It did!)

This is, incidentally, in my opinion one of the best ways of using LLMs with Delphi at the moment: writing a self-contained piece of code where the LLM does the work under your control. (We don't 'vibe' code in this house.) The other good use case is using LLMs to find bugs in your code.

Side story: Just a few days ago I got stuck and instead of spending an hour looking for a bug, I asked Claude. It found not one but two bugs in under a minute.

The Implementation

Returning to my problem: I sat down, started Claude Code, and described my idea. I told it that I needed some wrapper, preferably a record, that would know how to work with different time sources and also prevent me from mixing different time sources in an expression.

After some thinking and getting more information from me, it came up with an idea that is still mostly unchanged in the current implementation. It also did two things that I almost never do (and which I certainly wouldn't do for experimental code) - it wrote documentation (GpTimestamp.md) and unit tests (GpTimestamp.UnitTests). Sadly, my logs for that initial session are lost :( (It was only later that I found out I had to add the `cleanupPeriodDays` setting to the settings.json configuration file to retain sessions for a longer period.)

It took Claude some time to determine how to compile code from the command line, but after that it was able to compile unit tests, detect errors, and fix the original code automatically. Excellent! My only complaint here is that Claude Code constantly asks whether it can run the test program, although I always reply with "Yes and do the same next time" (or whatever the exact wording is). (Because I care for my sanity, I'm not using `--dangerously-skip-permissions`.)

Side note: Later I asked Claude to encapsulate this knowledge and add it to the global Claude.md file so I don't constantly lose time on the same problem. Maybe that could be useful for others too, so here's my Claude.md. The entire Compiling and Running Delphi Code section was written by Claude Code.

Evolution and Refinement

When the original code was working, I started experimenting (over the next few weeks). In a classical programmer's approach, I started changing GpTimestamp into a "swiss army knife" unit (while Claude Code kindly updated code, unit tests, and documentation) before deciding that I was trying to do too much in one place. I changed GpTimestamp back to a bare-bones implementation (again, Claude did all the hard work).

Claude was again a great help during this phase. Without it I would do way less iterations and would most probably end with an inferior code compared to the current release.

It is quite interesting to explore how much work Claude Code does in the background. I managed to grab logs from five different sessions which you can examine to see what happens in the background:

All preserved logs are available on my GitHub.

Final Thoughts

The whole affair began as a Claude Code test, so you may want to hear what I think about the experience.

Did I like it? Yes, definitely!

Was Claude helpful? Yes, especially as it has no problems performing "dull" tasks (i.e., writing documentation and unit tests).

Was the process faster than manually writing the code? Yes and no. I would definitely have written the unit in the same time Claude did, especially as a few times I used Claude too much and had to wait a few hours before continuing, but I definitely wouldn't have written documentation in that time.

Will I use Claude Code again? Yes, definitely - unless CodeBot for Delphi performs better - but I haven't been able to test it yet.

No comments:

Post a Comment