Part 2. Implementation in Python, Javascript, C, C++. How to Look at Code Correctly and What is a String / String Literal?
First, let’s look at the implementation, without any comments.
What immediately catches the eye is that the complexity of the implementation increases: the code in Python looks the simplest, then Javascript is slightly more complex, followed by C being even more complex, and the code in C++ looks the most complex.
Python:
print("Hello, World!")
Javascript:
console.log("Hello, World!");
C:
#include <stdio.h>
int main() {
printf("Hello, World!");
}
C++:
#include <iostream>
int main() {
std::cout << "Hello, World!";
}
The simpler the language (like Python or JavaScript), the closer it is to natural language—but this simplicity comes at the cost of control. The language does a lot “for you,” hiding complex details.
C++, on the contrary, is more complex but gives you full control over the program—from memory management to the nuances of data transfer. This compromise of “simplicity vs. control” is fundamental in programming.
How to Look at Code Correctly?
When a person has already learned to write and read code, they often forget “how they perceived code at the very beginning, when they didn’t know how to program yet.”
When a person already has knowledge, they most often read code structurally, not sequentially: line by line.
We, however, will learn to look at code correctly from the start, mastering its structure.
You might not understand what I’m talking about right now. But later, with specific examples, you will understand what I mean.
So, you’re looking at the code (let’s say you’re dealing with these languages for the first time). What can you already recognize in it?
Obviously: the phrase "Hello, World!". Look carefully at the code in each block and find this phrase there.
Notice that this phrase is enclosed in double quotes " " everywhere.
Question: Why is the phrase "Hello, World!" enclosed in quotes? Why not just write it as is: without quotes?
Okay, let’s assume we wanted to save extra effort and be able to write the text we want to see on the screen without needing to enclose it in quotes. How would the computer then understand that, for example, print is a command, and Hello is a word we plan to output to the screen?
To avoid this confusion, the compiler (or translator), which will translate our program into machine code, requires: “please wrap the text, which for you is just text, in double quotes, and I will then understand that these are not (programming language) commands.”
Okay, we’ve found the first structural unit: the text "Hello, World!".
In programming, this is called a string or string literal—a sequence of characters intended for output or processing as text.
Let’s now extract it from the program so it doesn’t interfere with our perception of the rest. More precisely, let’s temporarily replace it with three dots ...
As if we were a neural network that recognized this element and is now removing it from consideration, continuing recognition further.
Python:
print(...)
Javascript:
console.log(...);
C:
#include <stdio.h>
int main() {
printf(...);
}
C++:
#include <iostream>
int main() {
std::cout << ...;
}