Transcription
Hello everyone!
Today, I have a mega useful video for those who are not yet familiar with programming. I will explain some not-so-obvious things in an accessible format—literally, what I would tell a friend if they asked me how to become a programmer.
Let's get started with the basics. A computer is constantly busy calculating something, and computers were originally created as machines to simplify accounting. Today, most people don't perform any mathematical calculations. Instead, they are constantly transforming data—uploading pictures to Instagram, watching videos on YouTube, playing games. All of this involves a huge amount of data that is somehow transformed.
The computer doesn't know that your picture is a picture; to it, it's just a set of zeros and ones. The size of any file on your computer is the amount of information stored in it. The more information, the higher the quality.
A bit is the smallest piece of information, either a one or a zero—there's a signal or there isn't. A byte typically consists of eight bits, and one byte can encode 256 different values because 2 to the power of 8 equals 256.
Combinatorics is probably the only part of mathematics that will definitely come in handy in programming, and you can learn it in just a couple of days.
Next, we have kilobytes, megabytes, gigabytes, terabytes. You get the idea. All programs, in one way or another, work with data, and all programming can be reduced to transforming one set of data into another. Your task as a programmer is to explain to the computer what it should do, as precisely as possible, and to ensure that other people can understand your code.
That's why programming languages were invented—not for the processor, which doesn't understand them anyway, but for people. The processor can only understand machine code, which is zeros and ones.
For example, this is what a program that outputs "Hello, world" to the console would look like in hexadecimal code for an x86 architecture processor. What looks like letters is actually numbers, just not in the decimal system but in hexadecimal.
Admit it, this is impossible to read as a human. To improve the situation, assembly language was invented. It's a programming language that allows you to write programs much more easily than in machine code, but it's still difficult.
Here's an example of a program in assembly language. No one has been writing in it for about 50 years; people only occasionally look at the assembly code that a program written in a higher-level language gets converted into, and even then, it's a very small part of programmers who need to do this.
So, what do we already know? The computer works with data, and we, as programmers, must make it process this data as we want. Data needs to be stored somewhere.
In the past, this was a problem, but now even a phone can have a terabyte disk. There are places to store information: we have processor registers, which have very little space; the processor cache, which has more space and stores part of the data from RAM that the processor accesses most frequently; and the RAM itself, where your programs, including the operating system, reside.
In these places, data can only exist as long as there is power, unlike hard drives, which are cheap and store data for a long time, but accessing data on a hard drive is too slow. A program that stored its data on a hard drive would work terribly slowly.
Any running program has a memory area that it occupies. Static memory is a known quantity in advance, while dynamic memory is allocated as needed.
As you understand, today, most applications you use load data that is not originally on your device; they come over the network, just as you send your data over the network. The place where all this data is stored is called a database. These are programs designed to work with data—not just for simple storage, otherwise, everything could be stored in text files, but for convenient access, searching, inserting, deleting, and similar operations.
My interest in programming significantly increased when, in my first year at university, our professor from the computer science department explained how databases work.
Let's consider an example with registration. When you register on a website by entering your username and password, this data is sent to the server, which undergoes mandatory processing to check that you are not trying to execute some malicious command in the database, like deleting an entire table, but are indeed sending valid data.
After that, the server makes a request to the database and adds your username and password to it. By the way, a special language called SQL is used for database queries. Your password is not stored in plain text; it is hashed so that even if someone steals the database, your password remains safe.
Security is a very important part of software design, and if the protection is weak, the server can simply be hacked, and all the information will fall into the hands of fraudsters. Unfortunately, this is a common story; over one and a half million cybercrimes occur annually just in Russia.
Microsoft, Yandex, and Mail are among the most high-profile cases in 2023. Companies need defenders—white hat hackers. They hack servers, look for vulnerabilities, and do this legally. They are well-paid, averaging 120,000 rubles, and sometimes salaries reach up to 10,000 dollars.
If you are interested in this topic, you should check out the online course "White Hat Hacker" from Skill Factory. Here, you will practice hacking and cyberattack skills using virtual platforms and participate in competitive hacking events. Participation in such events is valued by employers. You will also learn Linux, Windows, and how to code in Python and write scripts in SQL. By the end of the course, you will have a portfolio, and the school will help you find a job.
By the way, if for some reason you can't find a job, Skill Factory will refund your money; these conditions are outlined in the offer. If you want to make the world a little safer, click the link in the description. And with my promo code "Montana," you can get a 45% discount.
Skill Factory teaches those who get hired.
A database contains a lot of tables, just like in Excel, where there are columns and rows. But the main feature of databases is the relationships between these tables. Almost all the information you receive is stored in such databases.
What is essentially a post on Instagram? Correct, it's a record in a database with an ID, username, a link to the picture, a caption, an author, a list of those who liked it, comments, and a bunch of other parameters.
Any users, products in online stores, bank transfers, your gaming accounts with information about what skins you have and how much gold you have—all of this is stored in databases. To render this information in your graphical interface, a special request is made to the server. The server queries the database, finds the necessary data, and then it comes to your user interface in a format you are familiar with.
It's worth noting that the server is also a program that is constantly waiting for requests. Your computer can easily become a server while still being your personal computer. For example, if you run a Minecraft server on it and connect to it yourself, you will be both a client and a server from one machine.
I just wanted to clarify this so you don't think that servers always look a certain way.
Databases are a complex topic, but it's primitive to understand what they are and why they are needed if you plan to become a programmer.
For a more in-depth study, a lot of time and practice is needed. Before we continue, let's divide all programmers into system and application programmers.
System programmers write complex things like operating systems, compilers, and other low-level stuff. System programming is high-level and usually goes through university. Not because you will learn some secrets of programming at university, but because the average person will find it quite challenging to delve into system programming. In most universities, you will simply be forced to do it; you will have to submit labs.
The second type of programmers is application programmers. These guys write applications using products created by system programmers. Essentially, they take ready-made building blocks and assemble the necessary applications from them. Moreover, there is a much higher demand for application programmers than for system programmers.
In short, application programming is what you will likely want to do when you think about coding.
A common problem for beginners is choosing a programming language. I'll say right away: pick any—Python, Java, JavaScript, C++, PHP—it doesn't matter. You can randomly pick one from the top ten most popular languages. Any of these programming languages consists of the same constructs and essentially solves the same problems, namely performing actions on data.
The key point you need to understand is that different languages are just different tools. There is no better or worse. You wouldn't compare a hammer and a screwdriver; if you need to drive a nail, you take a hammer. If you need to unscrew a couple of bolts from a professor's chair, you take a screwdriver. It's that simple.
The same goes for programming languages. Java is great for secure transactions where people are willing to tolerate a bit longer program execution for safety, while C++ is needed where speed and full control in real-time systems are required, for example, for controlling a combat robot.
Why is that? Because Java has a garbage collector that you don't control. If you wrote a combat robot control system in Java, you could miss a fatal blow to the head when the garbage collector suddenly decides to free up some memory.
Many people who are not familiar with programming often think that C++ is the best language and that you should only write in it because it's complex and fast. Therefore, if you're not writing in C++, you're doing something wrong.
Even my girlfriend asked me why I write in some "garbage" instead of C++. This opinion is quite popular. The answer is that writing in C++ is difficult and expensive. If you need a simple Telegram bot for a café, writing it in C++ is just nonsense. Take Python and do it 20 times faster.
In C++, you allocate memory for your program and clean it up yourself. This can be both a plus and a minus because you constantly have to think about allocated memory, and if you mess up somewhere, a memory leak will occur, and your program will consume all the available RAM on the computer it runs on.
Due to the complexity and unnecessary nature of such functionality, most programming languages manage their memory themselves, giving programmers more time to think about implementing business tasks rather than debugging low-level errors.
What's the difference between C and C++ and why is there so much honor given to these languages? Why am I not telling you about, for example, C#?
Let's start from the beginning. In the early seventies, everyone mainly wrote in assembly language, which was difficult and time-consuming. Then C appeared, and with it, the level of abstraction significantly increased compared to assembly, where you had to keep track of what was in which register. To perform simple actions like addition, you had to write something like this.
Here's the same example in C. I mention this because C became groundbreaking in terms of human readability of code, but it was still tied to the machine for which you were writing.
C++ came out in the mid-eighties, about a decade after C was born. Its main features included object-oriented programming (OOP), although back then, no one knew what OOP would become. OOP is one of the programming paradigms; we won't touch on this topic today, but I'll just say that Java is maximally class-based, while JavaScript is multi-paradigmatic with a wide standard library.
This made C++ even more abstract than C, and it could be considered a truly high-level language. A library is someone else's already written code that you can simply take and use.
In many languages, there are package managers that allow you to install the necessary library in your project with one command, knowing only its name. Besides libraries, there are also frameworks—these are libraries on steroids that dictate how you should write code.
In short, another programming language on top of your own. Despite its age, C++ is still alive, and people are still writing in it.
A small feature worth knowing about C++ is that you can write like in C because it literally grew out of C, but this is considered bad coding style, and usually, no one does it.
I also mentioned C#—this is Microsoft's creation, very similar to Java, and it has nothing to do with C++ except for memory management.
It's also important to know about types in different languages. All typing can be divided into static and dynamic. C++ has static typing; to create a variable there, you must specify what type it will be. This is necessary for optimization and fast program execution.
It's very good if the program knows in advance about all data types and that they will not change. In contrast, JavaScript has dynamic typing, meaning you can change the data type of a variable at runtime, during program execution.
Besides potentially leading to errors, this also reduces the speed of your program because just because your variable is a number now doesn't guarantee it won't become a string in the future.
Phew! I hope it wasn't too boring. Please give some feedback in the comments about what you think of this format.
And if you are somehow not subscribed to my Telegram, the link will be in the description.
Returning to the question of choosing a language, just pick any because, in the beginning, there will be no difference for you. You will just be getting acquainted with the basics of programming, and switching languages in the future will not be a problem at all.
If I could start from scratch, I would choose Pascal because it's good for beginners—strict typing and understandable syntax. This is not just my opinion; it's the opinion of many people who teach programming at universities.
Let's be honest; this is unlikely to convince you to learn Pascal. So, I repeat for the third time: pick any language.
The choice of programming language as something important is highly overrated, and the capabilities of languages out of the box differ very little.
Here's a program that simply outputs the text "Hello" to the console in Python.
And here it is in C++.
As you can see, the syntax is quite different, but despite this, there is always the possibility to use branching like if-else and logical operators like AND, OR, and NOT.
For example, if the user is an admin or a moderator, output a message in the chat. This kind of code is constantly used in real programs; it's basic logic that programmers should also know.
In addition, there are loops like while and for that will execute as long as the condition is true.
Right now, I'm writing code in VS Code. Usually, code is written in an IDE, which is a special program with a lot of useful features inside.
This thing at the bottom is the terminal; that's how our ancestors communicated with computers—no graphical interfaces, desktops, or similar visuals.
In the terminal, I run my written programs. The example code I just showed you was written in JavaScript, and to execute a program in JavaScript, you need to ask Node to do it.
Node is a program that executes JavaScript. If I made an example in Python, I would ask to execute my code in Python.
In Java, you first need to compile the program into a separate file and only then execute it. The same goes for C++.
Why? Because Python and JavaScript are interpreted languages, meaning they are executed by another program that converts these files into bytecode, then executes it, and takes care of how it will be executed on different operating systems and processors.
Don't confuse bytecode with machine code; bytecode is executed by the language interpreter, while in compiled languages, all of this is handled by the compiler.
The compiler is a separate program; for example, Java has javac, and C++ has g++. But these are not the only compilers.
If desired, anyone can write their own compiler, but it's quite complex. If a compiled program in C or C++ is executed directly by your OS, which then passes everything to the processor, a compiled Java file is executed in the Java Virtual Machine.
Remember how, as a kid, you downloaded Java to run Minecraft? That was necessary for your computer to execute Java code.
Java runs on phones, refrigerators, and PCs, all thanks to its virtual machine.
If you ask me why Java isn't an interpreted language if it executes its code itself, the truth is a bit more complicated. The line between compiled and interpreted languages is just another abstraction.
In any case, the processor will only execute machine code. There are also various optimizations like JIT compilation, but that's already an advanced level.
For basic understanding, it's enough to know what I've explained.
Now, let's look at the code of a small program with fairly simple functionality and try to understand how it works.
But first, let's run our program and see what it can do.
We type `python3` and the name of the file. We are asked to enter our password. We enter the password, after which it returns whether our password was among the ones in the database we are searching.
I have only three lines here, but in reality, you can find very large files with passwords and check if your password is among them.
Now, let's look at the code. At the very top, there is a comment; it has nothing to do with the execution of the program. Developers sometimes leave them for other developers to describe what their code does.
The first thing that catches the eye is the colorful words. All programming is working with text, so syntax highlighting was invented to highlight code.
The keywords of Python are highlighted in purple. `def` is the declaration of a function. If you, like me, ditched math in the eleventh grade, understanding what a function is might be a bit challenging, but I'll explain it to you.
A function is a kind of portal. Imagine a portal like in Rick and Morty. You give it some data, and it transforms it and returns a result. This function takes `x` and returns its double value.
Our function is called `check_string_in_file` and takes one argument—the name of the file. We define the argument ourselves. Naming functions, classes, variables, and constants is crucial; it should be clear to others what your program does based on its name.
`with` is used for working with files. When we exit this block of code, the file will automatically close.
In Python, code blocks are regulated by indentation, while in most languages, they use curly braces.
Now we open a file called `text.txt` with read permissions; it is located in the same folder as our executable file. Then we assign to the variable `file_content` the result of calling the `readlines` function on our file.
`readlines` is a feature built into Python. We just read all the data from the file into a variable and made it into a list. A list is a data structure in Python that you can iterate over, meaning you can move through it.
Now we enter a loop that processes the lines from `file_content`, iterating over your lines. The code inside the loop will execute until the lines run out.
The code inside trims the line breaks and compares the current line it is on with what we passed to the function. If it finds a match, it exits the loop, returning true.
In the end, we compare each word from the file with what we passed to our function, and only in the case of a match will it return true.
We are done with the first function. Now, the `main` function is called. This is the entry point of our program. It doesn't take any arguments; it just gets called for its side effect.
In it, we have a variable that stores the value entered by the user. Next, we call the function we declared above, passing it the user string. If this function returns true, we will see a message in the console saying that our password was found. Otherwise, we will see the opposite message.
You are unlikely to be impressed by the functionality of this program, and you probably want to write something big, cool, and useful right away. But to create complex programs, you need to know how to program, and the ability to program only begins with mastering a language.
After that, you need to get acquainted with how the processor, memory, internet, operating system, and databases work, learn a bunch of libraries, a couple of frameworks, and get familiar with tools like Git, without which you won't be able to work.
The most challenging part is learning how to design applications. Every large program consists of a bunch of folders nested within each other and files that ultimately connect to one another.
No one writes programs in a single file; they are divided into modules. Considering all this, there are a lot of rules about how you need to write code—literally about how to name files, how to arrange folders, what can be named in uppercase, and what cannot, and a bunch of other things that will seem strange to someone who has never programmed.
There are many books on this, and smart people love to discuss it, but you can only talk about architecture if you have solid experience writing code and creating programs.
I hope I was able to spark your interest in programming and that you learned something interesting.
Please let me know if you liked this format. Subscribe to my Telegram; there is a lot of valuable content there.
And if you want to support the channel, all the links are in the description.
Thank you for watching! See you next time! [music]