How does coding physically work?

154 viewsOtherTechnology

Like how exactly can a bunch of letters, numbers, and punctuation symbols make your computer do all kinds of things? Plus what happens inside the computer when it executes the code?

In: Technology

22 Answers

Anonymous 0 Comments

Imagine you have an electrical socket (just like what you have on the wall), multiple electrical devices, and a bunch of cables.

If you connect an electrical water pump to the socket using a cable, the pump runs. If you disconnect the cable, the pump stops. Of course connecting and disconnecting cable is dangerous, so let us use electrical switches instead. The pump is hot, so let’s connect a fan to the pump’s cable. Now whenever we switch the pump on the fan runs and when we switch the pump off the fan stops. We have just made our very first program! This is equivalent to:

if pump == ‘running’ then
fan = ‘running’
else
fan = ‘stop’
end

Notice that we cannot easily change this “program” because the way it works is completely tied to the way we connect the cables (or wires). This is why we have the phrase “hard-wired”, e.g., “I am hard-wired to be clumsy” which means I am clumsy and cannot change easily.

Now, our “program” only has two states: both pump and fan are running or both of them are not running. To have more states, we can connect more cables and switches such that:

* one cable connect the pump and fan to the electric socket
* one cable connect only the pump to the electric socket
* one cable connect only the fan to the electric socket

Then our program can reach any possible states: both of them are running, both of them are not running, and only one of them is running. Which state it has depends on which switch we press. As you can see, even two devices need so many cable and switches. When you have more devices, you need to have more cables and switches.

Not too long ago, scientists and engineers invented a microtransistor, which you can think of as a very small electrical switch. So small in fact, that you can fit millions if not billions inside your computer. Just like in our example, these “switches” control “devices”, e.g. each individual “tiny lamp” on your screen, also known as a pixel. Hope that helps

You are viewing 1 out of 22 answers, click here to view all answers.