Incompetent people and Low-level programming
Incompetent people and Low-level programming
I know people who are very competent in the cybersecurity field, like me, but there are not many. I was always wondering for a long time, why do people avoid getting into low-level computing? Is it because they are afraid of difficulty? Is it because low-level programming is not as interesting as back-end development, for example? Or is it because many people don’t really have enough brain cells to comprehend how stones can calculate? (Yes, computers are made of “stones.” Basically, it’s silicon, copper, gold, aluminum, iron, and plastic, but you get the idea. The CPU IS A STONE!!!).
The internet is full of foolish memes
You know what I always hated? Stupid internet memes about I.T. Those memes were never written by adept people, so the memes looked silly. I saw that those types of memes would get thousands of likes, and comments were full of “Hahaa… True man, it’s true!” No, it is not true. The type of meme I’m talking about is the one that compares two VERY different programming languages to each other. For example: C++ and Python. Those two are completely different, and they should never be compared. Python might be used for Web development or AI training, but you can’t develop a web API by only using C++ (technically possible, but it’s going to be a waste of time). On the other hand, if you want to write a controller for a robot or you want to program something that does complex operations very fast, C++ is the way to go (most of the times).
How do people compare them? Those memes say that Python is cooler because it only takes a single line to print something in the terminal, while you need to do complex “stuff” in C++ to get the same result:
1 | |
and
1 | |
These two pieces of code do the same thing. The only difference is the language. According to “Facebook dummies” (I am going to call them this from now on), Python is better. Why would somebody write so much code just for a simple operation…? Did they just call printing a simple operation???
For computers nothing is simple. Even if someone wants to print a text in the console. For a computer, that’s a HUGE task. That’s because the computer is running a kernel that runs multiple user-mode processes that talk to each other and to the kernel. The kernel also has drivers that talk to hardware (some drivers are not meant for controlling hardware). Let’s discuss what happens when somebody wants to print something in the console.
Deep dive
First of all, there is a kernel. Nothing happens without a kernel (there are some exceptions, of course). For example, fibers are user-mode threads, and the kernel does not control them. When the user calls Python interpreter and passes a file as an argument like this:
1 | |
The kernel is hosting a user-mode process, which is a terminal emulator application. When you open a new terminal emulator instance, it sends fork system call to the kernel and asks to create a child process for the shell instance. Remember, the terminal itself is not running commands. The terminal is just a host for the shell. The shell is going to be Bash on most modern Linux operating systems (distributions).
When you press something on the keyboard to type a command, the kernel receives an “interrupt.” An interrupt is an OS concept. It basically tells the kernel that something important is happening and the kernel should stop whatever it’s doing to handle the interrupt. This explanation is very brief but enough for now.
The kernel is going to receive an interrupt in the keyboard driver (yes, the keyboard driver operates in the kernel space). Then the driver decodes raw data and passes it to TTY subsystem. It sends received data to the kernel buffer, and finally, the user-mode process (terminal emulator) receives the data via read system call.
If you did not know, a system call is an action when the user-mode process asks the kernel to do something for it (user-mode processes do not have access to many things). Without the kernel, they can’t even write something in a file.
Back to the topic. When the shell instance receives the command, it parses the string and tokenizes the parsed string. Here, the kernel won’t be necessary. The kernel must be called if the process wants to allocate memory for the parsed string. The first token is going to be python3, so the shell instance (user-mode process) will call the kernel’s fs subsystem (file system subsystem) and ask it to look for python3 file inside /bin, /sbin, /usr/bin, /usr/sbin or any other directory that’s specified in the environment (on Windows it’s quite different; I mean the process of file search and where the file is looked for). Now, if the kernel fails to find the file, the shell will say that the command was not found. On the other hand, if the kernel manages to find the file, it’ll try to create a child process under the shell instance. It’ll first allocate memory for a new process. After that, the kernel will map the file into allocated memory. Then it’ll start the execution. Note that this child process is python3 interpreter.
python3 process is going to receive my_[code.py](http://code.py) as a parameter. It assumes that it’s a file, so it’ll look for that file in the local directory. Guess that’s required to do that? Yes! A system call. Jackpot! The help of the kernel is needed again. When it finds the file, it’ll read its content (another system call is required for that. Well, one system call to open a file descriptor, another one to read the content, and finally, one more system call is needed to close the file descriptor). After it obtains the content, it’ll execute the code. Note that python3 has its own STD libraries. Behind print function there are hundreds, if not thousands, of lines of Python code.
Did you get that?
Most of the people who make memes like that have no idea that any of those things that I mentioned above happen during code execution. Please note that Deep dive was not as deep as you think it was.
To understand all of that, you just need to start using low-level languages. Just switch from Python to C++. Don’t lie to me; I know that you’re unemployed. Don’t act as if you stop using Python, you’ll lose your job. You’re just sitting in your home and watching Indians write Django/Flask code that you don’t even understand. I can say that high-level languages make the brain ROT faster. Yes, the brain rots when you write print function instead of adding the standard I/O library and using std namespace to call cout function. It’s just better for the brain; trust me, I know.
How did I get here? Of course, I started from nothing. Nobody is born with the knowledge that I have. There was a time when I also did not understand computers. But now I do. Actually, the first programming language that I learned was C++. Most of the people say that beginners should start from Python because it’s easy to learn and use. I disagree. Yes, because when people try to learn In high-level programming languages, everything is handled for them. They don’t even need to manually allocate memory. They just press random keys on the keyboard, and magic happens. Let’s take a look at this Python code:
1 | |
What do you see there? Well, of course, an array. Nothing too confusing, am I right? No! The problem is that the array have many different data types inside. For example, the first element is a 4-byte integer. The second element might be a 4-byte float or an 8-byte double. The next one is char that takes 1 byte in memory. The next element is a bool, and it also takes up 1 byte of memory. The last one… It’s not even a data type; it’s just const char* pointer to char array. Computers can’t have arrays that have elements whose data types are different. Hundreds, if not thousands, of lines of C/C++ code are used to have an array in Python that’ll store elements with different data types.
In order for a low-level developer to have that kind of array, one must allocate the memory for the first element and put the element inside. Then, he must reallocate that memory (make it larger) to fit the size of the second element. For example, if the first element was a 4-byte integer, initial allocation is going to be 4 bytes. If the second element is a 64-bit pointer, the reallocation will add 8 bytes. So now the array is 12 bytes in size.
Yes, there are dynamic arrays too in C++ such as std::vector but it cannot have elements whose data types differ:
1 | |
Here, strings vector will contain char pointers that point to different strings.
When you start to see the beauty
After hundreds of hours of studying and practicing, you’ll finally see how beautiful low-level programming really is. It’s also cool. I can go to any hackathon and boast about my Assembly skills. Let’s write a simple Hello, World! application in Assembly for x64 architecture:
1 | |
This will do the same as C++ and Python code that I showed above. I don’t see why it is hard to understand. Let’s break everything down. We all know that Linux is an open-source project. Because of that, we know every system call number that the kernel accepts. Modern Linux works this way: Before the system call, several registers must hold necessary values. For example, before the first system call, I put 1 into RAX register. That’s the system call number. RAX always holds the system call number. After that come parameters. This is the order of parameters: RDI, RSI, RDX, r10, r8, r9. Those are 64-bit registers. When the system call happens, the output from the function that was called is written inside RAX. For example, if I call socket function and it fails to create a socket file descriptor, it’ll put -1 into RAX. On the other hand, if it succeeds, RAX will hold the file descriptor of the created socket. That’s the whole point.
Note that not every function can be called via system calls. For example, if you think that you can call strcmp function, you’re wrong because it is not part of the kernel. strcmp function is defined in strings.h header, and it is a user-mode function.
Those memes cause people’s minds to become smooth
Everybody knows, when someone is smart, his brain is not smooth. It has many wrinkles on it. After experimenting, I found out that those internet memes about IT and programming make people dumb.
The situation where you don’t need to think… That should always be avoided. I don’t mean to get into life-threatening situations and think about how to survive. In my opinion, developers were much smarter several decades ago. I have to admit, I’m still impressed by my math teacher. Before she started working as a teacher in my school, she used to write GPU drivers in Assembly in the late 90s and early 2000s. If that’s not impressive, I don’t know what is. That’s why she was a very good math teacher. Her brain was operating on another level. Now what… People just open up their laptops, type youtube.com and watch Python tutorials about making 3D games with Pygame. I must discuss this too…
I can’t stand when people post online about their progress in Pygame Python library. Like, are you crazy? Do you know what OpenGL is? Do you know what Vulkan is? Do you know what DirectX is? Look at people who develop 3D game engines. They choose OpenGL and C++ for a reason. In order to write a complex game, it must be optimized as much as possible. Python has so many abstraction layers that it takes centuries to even print something in the console compared to C++. You’re telling me that your unoptimized code will render a Blender model that has over 200,000 vertices and triangles over 200 times per second? I don’t think so. Graphics APIs exist for a reason. The best part is that Pygame is using OpenGL:
1 | |
This just creates 800x600 window and lets OpenGL handle the rest. It still is going to be 1000 times slower than C++ code.
My point is fewer lines does not mean better. Fewer lines mean more performance loss and more brain damage.
Summary
To sum it all up, I would say that I hate every Python or front-end developer in general. Yes, I know that Python has nothing to do with front-end development, but still. It’s just… then everyone wants to get a job. That’s the whole problem for them and paradox for me. Nobody wants to work hard, and everyone wants to get a job. Currently in Georgia, EVERY single person that I know who is into I.T. or programming, wants to get into front-end development. In the best case, they want to become a back-end developer who writes in C#. The paradox is that there is too large a supply of front-end developers and not enough demand.
So, when someone says something like: “Python is better than C++! Ahahaha Why write more than 10 lines of code when you can import a 3rd-party library in Python?” Just slap them real hard. Many of the 3rd party libraries are malware too…