Bits of things

That's been oddly bugging me since it got put forward. It's an affront. An offense. And just how do you explain computer programming to someone that doesn't do these things?

Ya know, it's a bit of a stumper. I've never thought much over it as it's something I have done since I was yay high. It comes to mind as trying to explain breathing. Though with less consequence if your explanation is in error. But that hardly explains how to do it and neither will this. But, do you have a dollar store calculator?

The easy part



It's got all the basic math bobs; add, subtract, multiply, and divide. Maybe even a square root button. It almost certainly has a memory store and memory recall button that no one uses. Which means it's only missing one bit. So here's a Todo list for you and your calculator:

1. Add 5 and 3.
2. Multiply by 4.
3. Is the answer larger than 100?
a. No, jump back to step 2.
4. Subtract 3.
5. Done.


Brainless, eh? But your calculator can't follow the instruction sheet on its own. More importantly, it can't jump backwards to step 2 and repeat previous steps. And that makes all the difference. To turn a calculator into a computer you need to be able to hop to a different step in the list whenever you need. Which means nothing if the calculator isn't reading the instruction list itself. And so we do that.

Write the Todo list on a sheet of paper. Hand your eldest kid the calculator and the instructions and tell him or her to get crackin'. You have now created your first general purpose computing device and may be good for a few patents. Eh wot? It's a sustainable computer built from biotechnology. Of course it's good it for a patent or two.

But that one little hitch at step 3 where we either needed to hop somewhere else or keep truckin' along is the keystone in the whole affair. What nerds call a Branch has the Lit Crit sorts pulling out Frost and taking the road less traveled. It's all just the ability to have a fork in the road and do something sensible with it. Without which we're just as well off with slide rules and abacuses. Abacii. Beads on bars. As notwithstanding Everquest and Porn, computers are all about random left turns. So long as understand this you get the gist of it all and it only gets more tedious from here.

Just another nibble



This is remarkably unimpressive until you want more than just the one Memory Store button. You want 8 billion of them and a pencil sharpener for your eldest. So now let's make a Great_Todo list:

7. Let i = 0
8. Do Todo list.
9. Store the results in Memory button number i.
10. Let i = 1 + i.
11.Is i equal to 100?
a. No, jump back to step 1.
12.Done.


Which is a great bit of pants, really. All we'd really like to say is "Do Todo list 100 times." But that doesn't tell anyone where to stick the results so they can be found in a reasonable manner later on. Or even if they should be kept at all or used as nourishment. As nourishment is very important for budding teens one simply can't tell what's going to happen unless you're very precise.

Just like before we're looping back on ourselves and doing the same thing multiple times. Unlike before we're now hopping to some named bob -- the original Todo list -- rather than rewriting the same instructions right here in the new list. Which is quite a bit of cheating on my part since we've got this whole 'i' business going on. Just what the heck is 'i' and where does it come from?

Anywhere you want really. If you walk it through we're using Memory buttons 0 through 99. Which is 100 of them, natch. (Programmers love zero, it is absolutely the best number in the world.) But since we know we're using those already we know we can't put 'i' in any of them or very strange things will happen. Other than that we don't really care where it gets off to. We've got 8 billion memory buttons available and we don't need it for anything but making sure we do the Todo list 100 times. So we'll just say we're stuffing that in Memory button 1012 and call it a day.

All that matters is that someone, anyone, knows where it got off to when and while they need it. This works for you, and it works for me, and your child most certainly doesn't eat glue sticks. But Intel does. The computer isn't a mind reader and doesn't have moments of reflection on its place in the universe. Which is why you can totally get a patent on your child.

So we can either rewrite the entire Great_Todo list to be painfully specific about which Memory Button to use for this throwaway value or we can write a tool that will do it on our behalf. Which is what programmers have done because it's a fantastic way to be constructively lazy. Programmers call it a compiler and you're going to call it your spouse. So hand the instruction list to your better half and tell them to assign all the random names you used a proper memory button, rewrite the list to reflect that, and give it back to you. Now you hand your proper set of instructions to your Green computing device and we're back in business.

But when code monkeys get on about variables this is what they mean. They don't mean high school math such as: 10 = 5 - x, solve for x. They mean that it's a handy name to give to a repeatedly used value as a refererce to the postal address it will eventually get; especially when we're really unconcerned about what postal address that might be. You always can, as we did with the results of each run through Todo, specify that address directly by number. And everything always will get a numbered address at some point. It just makes life cleaner to not care when we don't care. If not, then what was the point of getting married in the first place?

Byte me



The whole affair is about being painfully explicit at every step of the way because we are dealing with nothing more than a glorified teenager with a calculator. And it should start to seem a great deal like the nonsense forms you have to go through when filling taxes as part of your Spring rituals. So explicit in fact that you'll notice I've breezed right by another problem. We hopped from Great_Todo to Todo in step 8 but as we've no memory unless we stuff something in one of 8 billion buttons... So how did we get back to do step 9? There had to be magic, or it had to fall from step 5 to step 7 and restart everything from unfortunate scratch... Or your spouse did something you didn't expect when they translated the instructions from 'shopping list' to 'angst.'

If anyone can jump into Todo, or really any step, from anywhere then how do we know how to get back to where we want to be next? You've got a memory button for that. We want to do Step 9 after Todo is done, so we only need stuff a 9 somewhere in one of the random addresses before we hop from one to the other in step 8. All that we need do is rewrite Step 5 to pull up what's stored in the same button and jump to the step it finds numbered there. Poof, done. We can store any value in that button and when Todo gets done it'll haul up that value and hop to that step next. Which is, for what it's worth, much more pleasant than trying to follow IRS forms. Programmers used to call this a subroutine, then a function, and now a function is literally anything and everything to the language wonks. But subroutine will do. The only notion here is that, instead of simply stopping when done, it will haul up some stored location and continue things from there.

By this point, if you're not crafting Voodoo dolls, you might be asking why you're reminded of Amnesiacs and Alzheimer's patients. It's a blessed bit of our existence that we can take the notion of short term memory for granted. It just works. So we can worry about greater and grander things than labelling the kitchen drawers with Post-it notes. But it's the same sort of consequence when you hand a child a calculator. Nothing will be remembered unless you force it to be remembered. Not even if you want to remember where you put something to remember. The totality of existence is a Film Noir plot involving a bump on the head.

A great deal of the time you can just suss this out by handing your spouse the list and letting him/her deal with the fiddly details. But with all that jumping around here and there it becomes quite common to be absolutely unaware of where you're supposed to go next, where you came from, and who Billy is. As a consequence, and for those times, you just need a special memory button that doesn't act like a single value at all. It simply needs to keep a breadcrumb trail for you. Such that when you put a new crumb on the trail it keeps all the other crumbs nice and tidy underneath. And when you're done with the current crumb you simply eat it for nourishment so that the next crumb is ready to go. Which is the stack, so called, and allows you to remember as much or little as you like in only a single named place. Well, for various values of 'much.'

This blissfully blank-minded existence is a foreign concept outside the nursing field and is without question the hardest thing for folks to wrap their head around. We're all accustomed to some minimal exhibition of cognizance from the inhabitants of a universe and have our habits to suit. Tell your dog to 'heel' and they'll sort out the little details to get it done. If they don't pull it off properly you can correct them until they do. They are able to learn as they go. Glass computing devices are more akin to a 2 year old that never ages. They are horribly literal, have very little comprehension, and zero capacity for remembering things. Everything else is just a dollar store calculator.

Billy!



The preferred solution to all this isn't to use that minimal cognizance to learn how to deal with Alzheimer's patients; it's to get a new spouse. Hey, this is America, man. And there's some reasonable justification for that as programming generally involves writing a Todo list and then watching the machine burp up garbage for a bit. Thereafter you furrow your brow and dive into the code in a quest to figure out just where you made an assumption that neither your spouse nor your child caught onto like you desired. And since you're stuck with the child you're stuck with? Well, a new spouse ought work.

But the forgetfullness is so pervasive that the glass even does the math backwards. Mathemticians, and the rest of us for being taught this way, are very happy writing out things in bog standard form as: 5 + 3. None of us really think about it a great deal but we end up parsing the thing from the outside in. Which is par for the course as that's how your brain runs about while reading the words in this post. So long as the words are all the right length and the first and last letters correct it matters very little what the rest of them are:

Ygu chn rjhd tkjs sasdlkbe.


Slow, painful, and doable. We take each word boundary and bracket it out. Thereafter we take the first and last letter and bracket out what the rest ought be. And only then do we bother with the middle for confirmation. And without catching on to things we have to remember what we're doing at each step of the way. Such that when we see '5 + 3' we bust it out from the outside in, stocking back the 5 and 3 before we ever worry about the whole '+' part.

With a bit of inspection it ought really seem the most natural way to go about things. After all it doesn't do us to stock back the '5', and then the '+' before finally looping around after the '3', reordering everything, and doing it right. It makes sense to say we ought take the '+' first and then know we need two numbers and it makes sense to say we need the two numbers before the '+.' It likely seems most sensible to you to state that it ought be '+ 5 3' rather than '5 3 +.'

But you do not have a bump on the head. If we take the '+' first we need to remember it all along until we're complete. If we take the values first we never need care. The values simply go where they've been sent. And the '+' only need do the same thing every time without further need for reminisence. When it shows up it simply grabs any pair of values that happen to be where every value is expected to be in advance and chuck the answer out directly in one swell foop. If you're old enough you'll probably remember that adding machines worked in exactly this fashion as well. If you're not that old then you've either used an HP12C calculator or you're scratching your head at this point. What's odd here is that mechanical calculators have always performed in this manner; even back to the Stepped Reckoner some few centuries ago.

But to really 'get' computer programming beyond the idea of a Todo list is to accept that everything works backward from what you expect. The glass is running forward in reverse wearing a hockey mask on gigahertz. By fixing the locations that the adder will pull up the values to perform addition on we turn the entire discussion from one of performing addition on a pair of numbers to simply adding whatever happens to be there. The numbers exist or don't but the addition is happening full tilt regardless. You don't add numbers, you just take the results of an addition and like it.

If you haven't had a moment much like discussing cutlery with a bald kid camped in a New York flat then you'll want to go through it again.

It's a bit philosophical and not perfectly accurate, but that's hardly the point when picking out wedding rings. Just consider that the computer never stops constantly adding. Subracting, multiplying and all the rest as well. You don't particularly command the computer to do anything so much as you formally state your acceptance of whatever particular result it has generated this time around. Because it's an amnesiac and doesn't know anything else; not even what it's adding.

So when you want to add something on purpose you need sneak the numbers in and then allow the computer to pour the results into you. When you want to jump from here to step 9 you don't tell the computer to jump. You simply sneak the step number into the program counter and the allow it to pour the instructions in. This is all terribly wrong from normal perspectives in that we are the one's in control of the computer. And we are of course, I'm not putting forth some Digital Calvinism as the way of things. But one does not dictate the computer to add 5 and 3. One puts 5 and 3 in the right place and then accepts the sum. It's entirely backwards and everyone is Billy.

And it really makes the programming even less sexy than it already is as not even the Germans get fetishized kicks out of dressing in vinyl for a pocket calculator. (Rule 34, they do now.) But the proper definition of computer programming is not to perform math, or to make the computer perform math and leap through the code while Swan Lake plays. It's to don a gimp suit and move data around inside the machine so that things happen in your desired order.

Lots of folks that make a living at this will gripe about the description. Probably because of the Germans. But putting aside random cockups all bugs can be traced to a misplaced belief that the glass remembers things. And the greatest driver for new spouses is the notion that this one, this time, will free us from the need to order and remember things that the glass can't. If you've had your spoon moment and don't require such a crutch then the only thing a spouse can do is prevent you from moving the data around; which is hopefully benign. If you haven't then you're still waiting on a spouse that craps rainbows and smears you with sex appeal.

This last section was far too Unibomber Manifesto for good conscience or public sight. But it's here anyways, so what the heck. Everything from here, and the near totality of the Comp Sci field, is centered on how to move that data around in a manner that is pleasing and allows you to remember where you put your memories without being able to remember things. Which is mostly harmless but generally uninteresting. And it requires lots of drawings that I haven't bothered with. No really, none of it is intelligible without a whiteboard.

4 comments:

fred said...

Unless I'm missing something... wasn't that supposed to be:

Ygu chn rjhd tkjs sasdlkbe

(u instead of o)

???

Giraffe said...

I used to like programming, and was good at it. I used basic, and then quickbasic.

I didn't have much trouble understanding the language or structure.

But I never got further than basic BASIC.

Jquip said...

fred: Good to see ya. And uh... yeh. I put in typo in my studied typos... Danke, fixed.

Giraffe: Don't sell yourself short. With modern languages about most people don't get so far as to do Basic.

fred said...

Yep on the typo. Thought so but it was devilishly hard to read that sentence ;).

So bad...