In this day and age of AI, can we answer this simple question, Why do we write code We write code to tell computers to do what we want it to do for example If i need to interact with my smartphone essentially looking up a notification, we have baked this into code that when user swipes this way a notification if exists show it to user. This is why we write code to tell the computer to do what we want it to do
Why do we need code in the first place?
That’s a great question, why can’t we just make our computers in this way that it understands English, well that’s not a good point. It seems like AI (apparently) is doing just that it lets humans like us who doesn’t know code in any way interact with computers through plain language. But the question remains because even though i could tell AI to tell the computer to do this. AI too actually codes it, so essentially the superpower is not the computer or the AI but actually “code”. So code let’s us do whatever we want Again the question remains why “code”. because actually code is not ambiguous at all. Computers are really just a large logic machine you tell it this is how you should react at this and it would exactly the same thing. The problem with English is that it’s ambiguous not to us because we have been practicing it daily so we kinda understand the meaning of “this”, “that”, “where”, “here” and maybe dozen more. But what about the logic machine? Actually it needs really really strict instructions and this is where code comes in.
Now the next question is how do computers do that. What really happens when we write code
Computer and the code
Now the next question is how do computers do that. What really happens when we write code. Now to understand this we have two aspects the computer and the code itself For simplicity i will tell you that the code is just a magic language which somehow gets converted to something we call binary (binary means two i.e. 0’s and 1’s) So essentially whatever the code is written somehow gets converted into these 0’s and 1’s Now the question is who does this. What’s this magical thing which converts code into binary and that too not jargon binary a stream of 0’s and 1’s which actually is meaningful for the computer. This magical thing is another program called the compiler, the compiler is responsible for converting the code into it’s correct form of 0’s and 1’s. Now understand how does a compiler do this is a big task to explain in itself, Hence i am planning to create another blog which explores the inner workings of the compiler. But i think for now we could consider the compiler as a magic program which would give us the right value of 0’s and 1’s
So with this let’s move on to now the second piece of the puzzle, the computer the question is that with the compiler doing it’s job, the computer actually understands those 0’s and 1’s. How is that possible?
So let’s pose another question Why 0’s and 1’s why not just plain code
Why do we need binary system
Well there are multitude of reasons why and we will explore some of them
- Computers are electronic machines and the electronics are always made in such a way that they understand 0’s and 1’s easily, well it’s just either on or off all electronic components works on this theory example vacumm tubes, even when there wasn’t a computer still for mechanical machines we used punch cards which again comes back to 0’s and 1’s.
- Binary is much more reliable as compared any other thing, we would never need a whole scale of values for example take electrical signals here. Let’s assume that the range of my electrical signals is 0-5V. And now i define different numbers as values so maybe 0.5V, 1V, 1.5V, 2V, 2.5V, 3V, 3.5V, 4V, 4.5V, 5V assume all of these values so now the processor needs a very accurate way to measure this signal to get the correct value, and if by any chance there seems to be some noise added in the system there is a very high chance that the value calculated is wrong so now i have to make very very accurate systems to detect values, that is easy to make but also i have to create wires or ways for the electricity to travel very reliably is this possible, no not at all cause noise by default is introduced by nature and we can’t do anything about it. Hence it’s way better to reduce the values into two 0V, 5V anything in between could be rounded off to these two values and this makes the signal way more reliable hence binary is the way
- This one is something which i recognized while i was searching, actually many mathematical operations are actually very easy to do in binary
- Maybe you are asking that now we could probably innovate and bring in another system to help us be efficient, the answer is yes but the truth is it’s far more easier as the systems are already built for us, why do we need to reinvent the wheel when there are already things made upon this system example logic gates, transistors they are a beauty in research and we need to abandon it that seems wrong