Saturday, November 21, 2026

The Worst Code I've Ever Seen

A bit over a year ago I broke the only clipboard manager I liked at the time (mainly because it was a .jar file so I could run it at work). I downloaded its source code and tried to give it a dark mode. But it turns out, to do so, would basically be a complete rewrite.

I even had whatever AI I was using at the time attempt the dark mode update. It failed just like I had.

I just wanted a console looking, keyboard driven clipboard manager so I thought maybe I could get AI to code one in Rust. I actually wasn't really interested in coding such a thing I just wanted the app. It worked, I got most of the features I wanted - at least to start out with. BUT it tanked my CPU hard. Even when it wasn't visible, just monitoring the clipboard. After a week of yelling at AI:

"Bruh it's STILL hosing my CPU. Come on."

I decided maybe it was time to learn C++ in earnest... By having AI code a clipboard manager in the language then taking over it updates and maintenance myself.

Everything seemed great, it didn't make a dent iny CPU even after a week of it running non stop. However AI kept breaking the app just doing simple changes. Once it was ao bad I had to roll back a few commits. I realized I would need to dig into the code and see what was going on.

I was tweaking the behavior of one of the key bindings so I started with the if statements that drove key input processing.

AI had written the WORST code I had ever seen.

Windows/Linux checks were all over the place, making the code very difficult to read. The only way to determine what dialogue etc a key binding belonged to required tracing backward and forward to see what might be visible then what it might actually be doing.

So....

The first thing I did was write a Windows key code wrapper and a Linux one, so that I had ONE common set of key codes to work with, and they were intuitively named. Once that was there my key code ifs immediately got much cleaner.

Next I tracked down what each one belonged to and organized them, adding comments to make it even easier to see what groups went to what. Then I broke the implementation into methods. Now every check was an if and a method call. Very easy to read through all the key bindings.

After I made these changes the app never broke again. Yeah there have been bugs, but no full blown crashes or blank windows.

Well....

Until I tried to get AI to make a Wayland compatible piece.
I REALLY don't want to be forced into Wayland.

No comments:

Post a Comment

Project Structure Documentation Key

 I've added a 'key' to the documentation from comments Python script: structure So: //!_structure=/Project Structure Generates t...