A Pair of Coding Aphorisms

I write software for a living, and I take great pleasure when fixing a problem means reducing the number of lines of code in the system. In the last two days, I have come up with a couple of observations:

Every line of code is a pre-cancerous cell in the body of your application.

Now, “line of code” can be a deceptive measurement, as cramming a whole bunch of logic into a single line will certainly not make the application more robust. There are even robots that can comb through your code and sniff out overly-complex bits. But just as in humans weight is a proxy for a host of more meaningful health measurements, lines of code is the proxy for a host of complexity measurements.

But the point stands. I recently had to fix a bug where someone had copy/pasted code from one place to another. Then the original was modified, but not the copy. All those apparently-safe lines of code (already tested and everything!) were a liability, where instead a function call so everyone used the same code would have been more compact, easier to read, and much easier to maintain. There’s even an acronym for this type of practice: DRY — Don’t Repeat Yourself.

While that’s one of the more flagrant ways code bloat happens, there are plenty of others, mostly symptoms of not thinking the problem through carefully at the get-go, or not stopping to reconsider an approach as the problem is better-understood. Stopping and thinking will almost always get the project done sooner — and smaller.

One important thing to keep in mind is that programming languages are for the benefit of humans, not the machines that will eventually execute the program. If the purpose of your code is not obvious from reading it, go back and do it again. Comments explaining the code are generally an indication that the code itself is poorly written.

No software is so well-written that it ages gracefully.

I work on a lot of old code written by others, and I know people who work on old code written by me. In some cases, the code was shit to start with, but in others time has simply moved on, requirements have changed, and the code has been fiddled and futzed until the pristine original is lost to a host of semi-documented tweaks.

Naturally no code I have ever written falls into the “shit to start with” category (how could you even think that?), but that doesn’t mean the people who have to maintain that old stuff won’t be cursing my name now and then, as some clever optimization I did back in the day now completely breaks with a new requirement I didn’t have to deal with at the time.

And sometimes even if the code itself is still just fine, the platform it runs on will change, and break stuff. Jer’s Novel Writer was pretty elegant back in the day, but now when I compile I get literally hundreds of warnings about “That’s not how we do things anymore.” Some parts of JersNW are simply broken now. When I no longer work where I do, I will likely rebuild the whole thing from scratch.

Speaking of work, I am very fortunate to work in an environment that allows us to trash applications and rebuild them from scratch every now and then. Having a tiny user base helps in this regard. And as we build the new apps, we can apply what we’ve learned and maybe the next system will age a little better than the one before. Maybe. But sure as the sun rises at the end of a long day of coding, someone will be cursing the new system before too long.


5 thoughts on “A Pair of Coding Aphorisms

  1. And it would seem the “sweet” button is also broken, and the creator of it is long gone. I’m sure I can fix it, but dang. I could find another that works already, but I would still have to move all the old sweet data over.

    I need an intern. Anybody want to be my intern? I will pay more than zero, and provide training in a skill that has a huge gig market.

  2. Hey there, any idea how I can retrieve my Jers Novel Writer files on my MacOS 10.13.6? When I try to open Jers Novel Writer it says, “Check with the developer to make sure Jers Novel Writer works with this version of macOS. You may need to reinstall the application. Be sure to install any available updates for the application and macOS.” All my writing from my college years is contained within Jers Novel Writer and I’m afraid I’ve lost it all. :-( Thanks for any help.

    • The files are in your file system, wherever you saved them (JersNW predates the “app maintains a library in some mystical location like iTunes” idiom).

      Unfortunately, there are time and legal obstacles to me getting JersNW working on the latest Mac OSses (I work for Apple now, and JersNW is a “competing product”.)

      JersNW leaned on the operating system to save its stuff, with a really cool system that restored the entire state of the User Interface for that document, rather than just the data to rebuild the UI. Saved me a ton of work. Then one day I looked at a raw file and somewhere along the way Apple had changed the file format to be XML. While that change was invisible to me as the coder, it’s a happy break for you.

      So when you find those files on your hard drive, you can open them with an ordinary text editor and your stuff will be there, mixed in with a bunch of gobbledygook. If you, or someone you know, is an XML whiz you could write a script to recover the data along with all the style and structure information, or you can just painfully copy-paste the words.

      I’m sorry I don’t have a better answer for you at this point.

Leave a Reply

Your email address will not be published. Required fields are marked *