Can a Programmer Write the Perfect Program? Not Without The Help of Others.

On the Programming Underground we usually talk about code theory or examples, but once in awhile I like to pull up a seat and chat about some of my programming thoughts. Yeah most people think about dinner, going out with friends, picking the kids up on their way home but I am an unusual person, even by programmer standards. My day is often consumed with thoughts about how to write better code, seeing if statements in my chicken noodle soup, pondering the code already out there and writing my next project. So on today’s episode, I would like to focus on an few thoughts I had recently about what it would take to have a perfectly working program. I am talking about a program that never fails or at least fails so rarely that when it happens you would be flabbergasted. I quickly realized it is impossible without the help from others and that is part of the problem. I dive into the topic on this episode of the Programming Underground!

Follow my logic here for a minute and assume that we want to make the perfect program. It is a tall feat for just a human to accomplish. We are prone to mistakes, it happens. However, what if we could code perfect and write all of OUR logic perfectly without error. Would that make it the perfect program? You may quickly say “Well of course, if we do not error, then how can it go wrong?”

I am here to argue that even if we learned everything we could and made not a single mistake, we would still have a program that is not perfect.. or at least has the potential of failing at no fault of our own. Why is that? Well, programs of any considerable size typically have to rely on something created by others. Whether that be a DLL written by someone else, an assembly, maybe a web service or web site, a file created by someone else etc. Even if that was all perfect we still have to run it on an OS that itself was written by others who are not perfect. The question arises “Can you build the perfect program on an imperfect system?” If you take that one step further, can that system be perfect if it is built on hardware that may not be perfect?

What I am trying to get at is that in order for you, the programmer, to create the absolutely perfect program we need help from all those before us right down to the hardware manufacturers. The higher we move up in abstraction, the more responsibility we have to take for other’s imperfections. It is a bit of a downer to think like that, but it is true and I believe some companies, like Apple, realize this. To help “purify” their platform and try to fight against crashing systems and buggy sub programs, Apple fiercely protects some of its underlying function calls or strictly regulates who has access to the platform’s guts. This is also a mechanism to protect their technology, trade secrets and suck the money out of others. But if only Apple can touch the guts, they can also implement the strictest protocols and standards to make sure mistakes don’t happen often. Making anything they expose to application developers as rock solid as they can be and thus allow programmers to take responsibility for their own mistakes. If their application crashes, it is because they did something wrong, not some error from their OS.

So I think in order to build the perfect system I would have to control every aspect of the chain leading up to my program as well. I have to write that error handler to compensate for some .NET or Java class not working correctly and bringing down my program. Their class may have a problem because it relied on some underlying OS API call that failed which might have failed because of a hardware failure or some other person’s mistake… or bad decision in implementation.

Now I don’t expect you to go out and reinvent the wheel, but don’t we all rely somehow on one another to do the right thing at their level in this chain? I think we should be asking for more accountability from those closer to the hardware (or the hardware manufacturers themselves) than having to take on a bunch of responsibility at the application level. Someone at a driver level should be held more accountable than someone who is writing an application when it comes to handling an error. The higher we go the more exponential the potential problems we have to keep track of. The less I have to worry about anticipating an error generated from another system, the more I can focus on my own errors.

But because we are all human, we all make mistakes. When the person at the driver level makes one mistake, the application developer may end up having to write code to protect against 5 different error scenarios.

I am just a bit tired of having to compensate for so many possible errors bubbling up from the depths of our machines. That is in addition to the ones I know I will make. If only we could go back in time with what we know now and redesign from the ground up. Then perhaps we would have finally reached that perfect program nirvana. We must do that sometime in the future because I don’t think Star Trek runs on Windows!

Thanks for reading! 🙂

About The Author

Martyr2 is the founder of the Coders Lexicon and author of the new ebooks "The Programmers Idea Book" and "Diagnosing the Problem" . He has been a programmer for over 25 years. He works for a hot application development company in Vancouver Canada which service some of the biggest tech companies in the world. He has won numerous awards for his mentoring in software development and contributes regularly to several communities around the web. He is an expert in numerous languages including .NET, PHP, C/C++, Java and more.