2025-08-26

Coding with AI

Yesterday, I used "generative ai" for something useful, for the first time.

I have done a few very small experiments using ChatGPT or Google Gemini to write or edit small chunks of code. Results were pretty mixed; debatably it was a net benefit, i.e. its output was actually worth the time it took to talk to the bot and review its output. But the benefit was very marginal.

Yesterday, I wanted to write a java program to help me find identical files on my computer. Basically read through every file in a directory, recursively, get some metadata (full path, size, last modified, and a hash of the contents), and write all of that to a single file.

This was a challenge, because my total experience with writing java was about 5 hours, 15 years ago. I could easily have written the same functionality in C#, at least for Windows specifically; but I'm now using linux and wanted to learn java. So I decided, instead of large amounts of time reading reference docs and Q&A sites, I would give this whole "new paradigm" I've been hearing about a chance.

I opted to use Google's Gemini, since I like the interface, and just because historically I've found Google to be much better than other companies at protecting data from hackers. I was overall very happy with the process and results. 

I started just asking for a program from nothing - which merely wrote an output file from a list of files. Then I modified the code, tested it, and asked the bot to add more functionality. This went on for hours, taking turns asking the bot for a modification, which I would often tweak myself even before trying to run it. In the end, I now have a simple utility which does exactly what I wanted.

For anyone who wants to try this, I strongly recommend reviewing all of the changes that the bot makes. using source control to help you review every change that the bot suggests. Every time I made a code change, I would:

  1. commit my code to git
  2. copy the full text into the chat bot interface
  3. have the bot make changes, possibly multiple
  4. copy the modified version back into my code
  5. manually review the git compare of all changes

Aside from ensuring no bugs are added to my own code, this also gives me a chance to learn some things that I might not have known before.

I'm sure I could have gotten the same basic functionality on my own, although it would have taken much longer -- probably double or triple the time. If I were experienced at java programming, I expect the time taken would be pretty close to break-even.

But the nice benefit of the ai assist was really in helping me identify a few things I hadn't thought of, or reconsider things I had just decided without any serious thought. Examples: 

  • It changed my main data-holding class to a "record", which I didn't know was a thing -- so therefore I could not have considered until I learned the java language better. (a "record" is closer to a "struct" which I know from .NET, although not really the same)
  • It changed the file reading from one large value, to instead read the data in chunks, which means using less RAM for large files. I thing this had crossed my mind already, but I would not have bothered myself, since I would have had to spend 10 minutes looking up how to do it, then another 10-20 minutes trying it out and making sure it worked as expected.
  • It suggested using SHA-256 instead of MD5. I had briefly considered which hash to use, or even just a checksum. Since a malicious user is not a real consideration in this utility, I had opted for just MD5 since it's very fast and pretty universally supported. But when it suggested SHA-256, I figured why not try it, so I did. The overall performance seems effectively identical, presumably the processing is all io-bound so adding some extra CPU cycles has no effect on runtime.

There were probably other things it added, but that's all I can recall at the moment. Now for what it *didn't* do, since it is not "actually intelligent".

  • It did not, at any time, seem to understand the purpose of the utility. That is, it never anticipated what my next instruction was, despite a large number of times that I asked it to suggest improvements. For example the biggest optimization by far was to skip recalculating the hash if it has already been done previously, i.e. if the saved (old) filename, size, and last modified date were identical then just keep the already calculated hash value.
  • It added lots of clutter, mostly in the form of code comments. Adding a 1 line comment to explain 1 line of basic code is not a benefit - aside from simply bloating the file and creating visual noise, it also adds a maintenance hazard of either 1) spending time keeping the comments updated or 2) having comments that do not match what the code actually does, which is just inviting future bugs.
  • It never adopted my coding style. I repeatedly deleted comments, changed variable declarations to be implicit (var x = new myClass();), and remove extra needless code-block sections. But every time the bot generated new code, it did not take the hint to make its additional code conform to the local patterns. Even worse it occasionally added comments to code it wasn't modifying, which I had just deleted. Eventually, I explicitly told it to stop adding comments which were obvious from the actual code, which did greatly reduce that noise although not entirely.

All in all, this was a very good experience, where the chat bot saved me time and improved my end result. But I believe I was at the perfect sweet spot for using ai assistance, namely an experienced developer trying to do something outside their area of expertise. I believe other use cases would also benefit, but not as much.

If I were a very inexperienced developer, yes arguably the help factor would have been much greater compared to doing the task without any assistance. But also, the final product would almost certainly not have been as good, missing significant code improvements for clarity (i.e. maintainability) and performance.

If I were very experienced in java, I would have been able to write a similarly functioning application in nearly the same amount of time. But I would have skimped on a few things. I suspect in the future I will end up fully writing the application, then feeding it to a bot as essentially a code-review to make suggestions.

2025-08-17

Ubuntu Chronicles - 3 Days

On August 15, 2025, I set up a new PC in Ubuntu. This will hopefully be my primary PC for a few years. But things happen! So this time, I am trying to do things the correct way, at least as best I can manage. This will require some thought, and doubtless I will encounter hurdles along the way. This blog is to record my thoughts, and especially document what I am doing so it will be easier to recover from disasters, or else just to help anyone who wants to follow my example, and/or learn from my mistakes.

Prelude: the Previous PC

Around May 1st, 2025 I was suddenly unable to boot my previous PC. It was actually a dual-boot machine with Windows and Linux (Kubuntu), and I could reach the boot menu, and open Windows. But this was a seriously under-powered machine, which worked great as a lean linux machine.

Since getting the machine, I had booted into Windows only a couple times; that had never been the plan. Windows 11 Home is simply a bad user experience even with the best hardware, and with this Beelink Mini PC it was simply untenable. So I considered the machine as lost, and not too long after ordered a new one.

(interlude: life was busy; played some games, touched grass, had some physical therapy)

Much later, shortly after my next PC was usable, I realized that I had made a diagnostic error. The old PC was not actually dead. I recall trying half-heartedly to see if I could make it work, but since I strongly suspected it was a failing hard-drive, I didn't put in much effort. I figured after the next PC was working, I would try recovering data and then chuck it. But I should have looked more closely -- the linux boot menu actually gave an Advanced option (always look at the Advanced options!) which allowed booting into the current version (which failed), its "safe" mode (which also failed), but also allowed booting into the previous version of linux, or its "safe" mode. And those actually worked. In short, the update to Kubuntu did not get along with some piece of my peculiar cheap hardware, probably a video driver. And after simply waiting a few months, booting from the older version and updating to the newest version actually did work, which means someone else found and fixed the problem. The ability of the linux community to resolve these problems never ceases to amaze.

In the end, now I have two working PCs, so the old machine is very conveniently available for data retrieval, and maybe I will find another use for it later.

New PC

First the specs. The new PC is actually barely better than the old one; debatably worse in some ways. Which is fine by me - linux really does not need the massive resources of  the Windows monster. Unless I start wanting to edit videos locally, I do not foresee any real need for more. So what is this tiny device made of?

  • Beelink Mini S - yup, I got more of the same line of uber-cheap hardware!
  • Architecture: 64 bit, 3400 MHz Intel CPU - because I do want compatibility with the old-world that I grew up in.
  • Memory:  512 GB hard drive, 16 GB RAM
  • Ports: 4 USB, 2 HDMI, 1 ethernet

Revenge of Windows

When shopping for the next PC, I read the specs of at least half a dozen devices, and somehow failed to notice that the one I ended up choosing came with only Windows 11 installed. I had intended to get another that was set to dual-boot, to minimize headaches, but mostly to mitigate the chance that I would be totally unable to install linux, because I have heard of some new PCs sold with UEFI that could not be disabled. (which I had never seen myself)

But c'est la vie, it had Windows. So I would have to vanquish that, and install linux from scratch myself. Armed with a few bootable USB drives, I set into the task; it was much more harrowing than expected, but persistence pays off.

  • Booting from any USB formatted in Windows was a failure. Yes, I turned on CSM in the BIOS, and tried toggling tons of settings.
    • SpinRite is still a sore spot here; that is a super low-level program that checks for and repairs bad sectors of hard drives. Alas, to date I have not succeeded in getting any version of it to run on this PC; nor on the previous Beelink Mini PC.
  • Booting from my old Kubuntu recovery USB worked, it would open the OS, and I could see the hard drive. But when I tried to simply install that operating system, it had a fatal crash, thus leaving the new PC in a fully broken state since now Windows was overwritten, and Kubuntu was not installed either.
  • What finally worked was bringing the old PC back online, and using that to create a new bootable USB drive to install Ubuntu.
    • Yes, I switched from Kubuntu to Ubuntu. Trying to keep things cleaner this time!
    • I would have preferred to do this from the new machine itself, simply booting from the Kubuntu recovery drive. But that O/S apparently did not have the drivers needed to enable wifi with the new hardware, and I didn't want to move the PC to the room where I have an ethernet cord.

Victory finally achieved! The new machine booted into Ubuntu, with all hardware working like a charm.

First Days - Recovery and Setup

One thing I want to do better is manage all the old data I have accumulated over decades, keeping proper backups but also removing duplicates where they are not intended. This means first pulling together just about everything I can find into one place. So over the next few days, this was many hours of copying flash-drives, external hard drives, CD backups, and going through all the old (windows) PCs that would still boot up (one would not). Actually organizing the data is not nearly completed, but at least I have all the files now on just the internal drive plus one external drive.

Next I installed some applications, here is the list of everything I have used so far:

  • Kate (text editor)
  • IntelliJ (software development)
  • Minecraft
  • Sound Juicer (to rip audio CDs)
  • AutoKey (macro tool)
    • so far this has been unusable from a bug; it seems to not intercept key presses which makes it pointless for my usage
  • Google Chrome (will probably uninstall after transition period)
  • Bitwarden (Firefox extension)
  • Pre-installed apps I have actually used:
    • Firefox - probably will stop using if Brave is as good as I hear
    • Terminal - might stop using if Kate and/or IntelliJ have a good version
    • basic core apps like Settings, Files, App Center, Calculator, Image Viewer
  • Planning to install soon:
    • Brave (browser)
    • Gimp (image editor)
    • VLC (audio/video player) 

Hopefully good things will follow in the coming weeks!