Saturday, July 16, 2022

Essay05 The Core of Computer Programming (part 1)

Essay05 The Core of Computer Programming (part 1)

A look at (simplified) computer system


The question is: What is essence of computer programming? What is the core of computer programming? What is it, that if you take away from the thing that is computer programming, will cause the thing to no longer be computer programming? My answer is: Conditional Branching (IF-GOTO).


This is a surprisingly deep issue. There are many considerations regarding this question. I had planned this to be just a single post, but having seen the whole, completed answer, I decided to split it into 2 parts. If you, like most people, think that the issue is a simple one, then I encourage you to stop at this point and work out your answer. Then continue reading, and compare our answers.


First, let me tell you what computer is not. There is an old joke that when a prospective buyer ask a salesman what the computer can do, the salesman answered that the computer can do half the things the customer can do. "Great! I'll take two!" Ha ha. Well, computers don't work like that. Computers can only do what you tell it to do, no more, no less. And whatever the computer was told to do, the computer can do it exceedingly fast, and with great accuracy.


Of course, fast is a relative term. Back on the old Apple 2 days, 1Mhz is fast, but not that fast. Yet, it is still much faster than Charles Babbage Analytical Engine. Nowadays, we have fast computers, but is it really that fast? Newer programs are such a bloat, that huge amount of computer resources are taken, not for working on the problem, but on cute animations that aren't that useful, or even cute, for that matter. So much waste.


We don't really need compilers or programming language, either. Computers are basically a collection of bits and bytes. Ones and Zeros. There's really not much more to it, until we get to Quantum mechanics. We do have CPU, but what is the core difference between a programmable calculator, and a computer? In simple terms, why is The Difference Engine a calculator, while the Analytical Engine a computer?


The most fundamental principle that is uniquely a computer program is, in my view, Conditional Branching. The ability to change the path of computation is fundamental of computer programming. If you have everything else except conditional branching, then you don't have a computer. What you have, then, is a batch processing. Imagine a robot that does a complicated dance, but repeatedly so without any change. Is that a robot? Yes. Is that a computer program? I'd say no. It's a complex mechanical construct, but not a computer. If, say, a car manufacturing robot can only be influenced by On and Off, then it's not a computer program, rather a batch processing. If, however, the robot can sense a car being somehow incorrectly staged and alerts the shop foreman, then it is a computer program. A computer program reacts to changing condition. A batch process cannot.


The simplest implementation of Conditional Branching that I can think of is IF-GOTO. This is true regardless of computer language. It can be Branch if Zero (BZ), Branch if Not Equal (BNE), IF-THEN-ELSE, WHILE/REPEAT LOOP, and other constructs. So, what does it mean, exactly that IF-GOTO exists?


Well, first of all, you need some kind of variables, and that variables can be compared. Variables means pointers. Pointers mean memory addresses to point to. Memory addresses can contain both code and data, but they are really just numbers. This means that GOTO address can be used to call functions. Combined with data stack, and you can call function recursively. You also need CPU because of the explosive combination between operation and data. CPU means you need some kind of flip-flop clock, in order for the CPU to process each instruction cleanly. 


The should also be some means of Input Output available. That means we need System Bus in order to shuffle data from Memory to CPU and vice-versa. We also want the computer system to interact with outside world. So, some kind of external data line, either serial, or maybe GPIO is in order. Interactive element can be Keyboard, Mouse, or Telemetry signal receiver. Output can be Display, Teletype, or maybe just some speakers.


Along the way, we can optimize further with Cache Memory or Co-Processor, but all things considered, the core of computer program is IF-GOTO. The rest is just there to support that process.


No comments:

Post a Comment