Yeah, of course, it's synchronous and single-threaded and that “farragos” thing… I know that! I think I can start with React now.
[Dramatization based on real-life events]
I don’t know about others but I, sure as hell, took my sweet amount of time to really know what all that “farragos” and alike, all meant. Being a good samaritan, I thought I should create a guide. This is for beginners and people like me who were in a hurry to skip the JS basics.
For learning the coding syntax and implementation, I always suggest starting with freecodecamp.org.
You know nothing, Jon Doe!
What does that mean? High-level language syntax looks closely like the English language more than it looks like the machine code. In contrast, a low-level language would look more closer to machine code though will not be machine code. This is how you code in a high-level language — a simple example of adding two numbers 1234 and 4321:
Computers don’t understand that, not really. They talk in machine code. Machine code is just combinations of 0s and 1s - the language of computers. It looks something like this (the same example of adding 1234 and 4321):
So now we have two entities — a computer and you, the user. Since we have two entities speaking different languages, we need a translator in order to enable a “conversation” between the two.
Fundamentally, we have three ways of these translations:
The assembler converts low-level assembly code into machine code — what’s assembly code? For now, it’s basically just a “placeholder instruction” of a combination of bits that mean something to your computer. You are more in control of instructing what the computer does, one instruction at a time. Example: I want to instruct my computer to allocate two bytes of storage to a variable “x” and initialize it with a value 23. The assembly language code would look like:
x: .word 23
How it's different from other approaches is that it just does a 1-on-1 translation of mnemonics and literally just replace the labels with their machine code counterpart.
Enough about assemblers though.
2. Compiler and Interpreter
A Compiler will “process” the source file to machine code (or bytecode) before executing while an Interpreter will start “reading” the source code one line at a time and start executing.
I’ll borrow Almog Adziashvili’s fun alcohol analogy to explain the difference.
Let’s make a Mojito!
You need —
* White Rum
* Fresh Lime Juice
* 2 teaspoons sugar
* 6 mint leaves
* Soda Water
We have two ways — the Compiler Way and the Interpreter Way.
Compiler Way: We gather all the ingredients and the amount of those ingredients required in one place. Now we add all these in a blender together to mix.
Interpreter Way: We take the blender glass and start getting the ingredients one at a time. First the White Rum from the bar cabinet, then we go to the refrigerator to get the lime juice and run the blender, then add the sugar and run the blender, and so on.
Voila! We have the mojito ready and it's going to taste the same both ways.
In a compilation, the time to build a compiled code (i.e. the ingredient preparation time) is longer than the interpreter way BUT the run time (i.e. the time to mix the ingredients) is less than the interpreter way.
Continuing on the example, you will have to gather the ingredients again before the blending part, whenever your mom has cleaned the kitchen again or you are making a mojito in a different house. So this process of building the compiled code is going to happen every time you want to run your source code after a change (however small) or in a different environment.
Closing argument: The compiler is usually more secure since the compiled code is just machine code. It needs no source code to run. So no source is exposed. This is faster and provides a ready-to-run executable on the machine.
The interpreter is faster during the development phase — quick debugging and can be run on any machine that can support it. A little slower on runtime but faster while creating prototypes.
Take your time to think. The elders call it interpreted. So it has a line by line execution way. Seems about right. Is it though?
Get your mind gears moving and once you’re ready — enter!
Originally posted on my blog: https://blog.chunkybyte.xyz/
Show me some love ❤