Saturday, 27 February 2021

The Unknotted Rope Analogy

A rope is a wonderful piece of crude machinery. It is designed to support great loads. With the right series of knots, it can fasten, hitch, bind and stop, among other things. There is a great deal of functionality within the humble rope if you know the right knot to use.

Yet, knots come with a caveat - they weaken the rope.

Too many knots.

A rope can support up to a certain amount of strain before it snaps. This is what is known as Breaking Strength. Knots lower the Breaking Strength of a rope... and the more knots are tied into a rope, the weaker it becomes.

And so it is with programming.

Code increases the functionality of a program. With more code, your program can achieve more things. But code also weakens the program. The more code you write, the more moving parts your program has, the more bugs and vulnerabilities inevitably work their way into your program.

For example...

Does your program connect to a database? Then that database connection can be hacked.

Does your program perform division? Then there is a possibility of a divide-by-zero exception.

Does your program perform string operations? Then there is a multitude of string-specific quirks you have to watch out for, such as character sets and special characters.

What's the solution, then?

Yikes, you were expecting a solution? This was only ever meant to be an analogy.

Kids, there is no solution. Unless you are writing a Hello World program, there is going to be the possibility of bugs. No two ways about it.

A Hello World program is like a single unknotted length of rope - beautiful, pristine, problem-free... and utterly useless on its own. Nothing useful was ever accomplished with a rope that had no knots tied in it, unless said usefulness amounted to acting as dead weight. Even if all you want to do with a rope is climb it, that rope has to be anchored to something else... usually using a knot of some kind.

But...!

There is, of course, a way to mitigate those risks. While we do not have to make our ropes or programs completely useless, we can limit the functionality of these things. A rope can be used to do one thing, while other ropes can be deployed to take care of other things. That way we won't have a case of one single rope handling multiple simultaneous uses.

Likewise, a program needs do do one thing. And any additional functionality can be outsourced to other components.

Knot a problem!
T___T

No comments:

Post a Comment