In my previous post I announced that the code formatter now supports inline if expressions (aka ternary operators). That was technically true, as long as these expressions were in one line of source code:
Value := if Condition then TrueValue else FalseValue;
But as soon as you tried to split longer expressions into multiple lines, the formatter failed miserably.
I put Claude Code on that. Let it create some test cases and work on an implementation. It took a whole day (*1) and failed, and in the end tried to trick me into accepting an incomplete solution. I caught that though and told it to “try harder” (Yes, I used exactly these words.) It took another day (*1) but managed to change the formatting code to make all tests pass.
I was a bit suspicious of the code though, because I was afraid it might have written it specifically to only pass the unit tests, so I asked it to create some more test cases. It did and some of them failed (Claude Code seems to be very good at creating unit tests. There were some tests which I had not even considered, like nesting the if Condition part.). So I had it to split the large tests it created into separate test cases for all tests that already work and one test for each case that failed. It did that too, but created expected files that did not match the correct formatting, so I had to adjust that too. (Is it trying to keep the human happy by letting him find and fix the occasional problem? 😉 ). Then I put it to fixing these failing tests. And today it succeeded. So I think the formatter support for the new Delphi syntax is now quite complete.
There is still no new GExperts release for this feature. If you want to use it, you must compile your own DLL.
Discussion about this blog post (link to be added later) in the international DelphiPraxis forum.
(*1: When I talk about Claude Code working on something “for a day” it actually means that I put it on a task and then do something else (like working on my day job 😉 ) and whenever I find some time look at what it has been doing and occasionally give it new instructions. Most of the time these “new instructions” just mean pressing Enter so it can execute some command that I have not yet (or don’t want to) allowed it to execute in general. So it does not really work on it “for a whole day”.)