📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

БАЗА ЧТОБЫ НАЧАТЬ ПРОГРАММИРОВАТЬ

Honey Montana16:17

Transcription

Hello everyone. Today will be a mega useful video for guys who are not yet familiar with programming. I will explain in an accessible format some non-obvious things, literally what I would tell a friend if he asked me how to become a programmer. Let's go. Let's start with the basics. The computer is constantly busy with something it calculates, and computers, in principle, originated precisely as machines to facilitate accounting. Today, most people do not perform any mathematical calculations. Instead, they constantly transform data. Uploading pictures to Instagram, watching videos on YouTube, playing games – all this is a huge amount of data that is somehow transformed. The computer has no idea that your picture is a picture; for it, it's a set of zeros and ones. The size of any file on your computer is the amount of information recorded in it. The more information, the higher the possible quality. A bit is the smallest piece of information, either one or zero, meaning there is a signal or no signal. A byte typically consists of eight bits, and with one byte, you can encode 256 different values because 2 to the power of 8 is 256. Combinatorics is perhaps the only part of mathematics that will definitely be useful to you, even a little bit, in programming. It can be learned in about a couple of days. Then comes kilobyte, megabyte, gigabyte, terabyte. Well, you get the idea. All programs, one way or another, work with data, and all programming could be reduced to transforming one piece of data into another. Your task as a programmer is to explain to the computer what it should do, and do it as precisely as possible, and so that your code can be understood by other people. That's why programming languages were invented, by the way. They are not for the processor; it doesn't understand them anyway. They are for people. The processor can only understand machine code, zeros and ones. This is how a program that outputs "Hello world" to the console would look for a processor on the x86 architecture. This is hexadecimal code. What looks like letters are actually numbers, just not in the decimal system, but in hexadecimal. You must agree that this is impossible for a human to read. To somehow improve the situation, assembler was invented. It's a programming language that allowed writing programs much simpler than in machine codes, but still difficult. Here's an example of a program in assembler. No one has written in it for about 50 years; only occasionally do they glance at the assembler code into which programs written in higher-level languages are converted, and even then, only a very small fraction of programmers who have a need for it do so. So, what do we already know? The computer works with data, and we, as programmers, must make it process this data as we wish. Data needs to be stored somewhere. It used to be a problem, but now even a phone can have a terabyte drive. Places where you can store some information include processor registers, where there is very little space; processor cache, where there is already more space, and part of the data from RAM is copied there, which the processor accesses most often. And then there's RAM itself, where your programs are located, including the operating system, which is also a program. 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 access to data on a hard drive is too slow, and a program that stored its data on a hard drive would work terribly slowly. Any running program has a memory area it occupies. Static memory is a predetermined amount, but dynamic memory is allocated as needed. As you understand, today most of the applications you use load data that is not initially on your device. It comes over the network, just as you send your data over the network. And the place where all this data is stored is called a database. These are programs designed for working with data, not just dumb storage; otherwise, you could store everything in plain text files. Instead, they offer convenient access, search, insertion, deletion, and similar operations. My interest in programming significantly increased when, in my first year of university, my lecturer from the computer science department explained how databases work. Let's consider the example of registration. When you register on a website, entering your login and password, this data is sent to the server. After that, it undergoes mandatory processing to check that you are not trying to execute some malicious command in the database, for example, to delete the entire table, but are actually sending valid data. After that, the server makes a request to the database and adds your login and password to it. By the way, a special language called SQL is used for database queries. Moreover, your password is not stored in plain text; it is hashed so that even if someone steals the database, your password will be safe. Security is generally a very important part of software design, and if the protection is weak, the server can simply be hacked, and then all the information will fall into the hands of criminals. Alas, this is a common occurrence; over one and a half million cybercrimes occur annually in Russia alone. Microsoft, Yandex, Mail are among the most high-profile cases. In 2023, companies need defenders – these are white hat hackers. They hack servers, look for vulnerabilities, and do it legally. They are paid very well for it, on average 120,000 rubles, and sometimes salaries reach $10,000. If you are interested in this topic, you should pay attention to the online course "White Hat Hacker" from Skill Factory. Here you will practice hacking and cyberattack skills using virtual platforms, as well as participate in sports hacking competitions. Participation in such events is valued by employers. You will also master Linux, Windows, learn Python, and write scripts in SQL. By the end of the training, you will form a portfolio and, with the help of the school, get a job. By the way, if it doesn't work out, Skill Factory will refund your money; these conditions are stated in the offer. If you want to make this world a little safer, follow the link in the description. And with my promo code MONTANA, get a 45% discount. Skill Factory teaches those who get hired. The database itself contains a bunch of tables, just like in Excel, with columns and rows. But the main feature of databases is the relationships between these tables, and almost all the information you receive is stored in such databases. What is essentially a post on Instagram? Correct, an entry in a database with an ID, a link to the image, a caption, the author, a list of those who liked it, comments, and a bunch of other parameters. Any users, products in online stores, bank transfers, your game accounts with information about what skins you have and how much gold you have – all this is stored in databases. To render this in your graphical interface, a special request is made to the server. The server accesses the database, finds the necessary data, and then it comes to your user interface in the familiar form. It should be noted that a server is also a program that constantly awaits requests. Your computer can easily become a server without ceasing to be your personal computer. For example, if you run a Minecraft server on it and connect to it yourself, then from one machine, you will simultaneously be both a client and a server. I'm just clarifying this so you don't think that servers always look like this. A database is a complex topic, but it's primitive to understand what it is and why it's needed if you plan to become a programmer. For more in-depth study, a lot of time and practice will be needed. Before we continue, let's divide all programmers into system and application programmers. System programmers write all sorts of complex things like operating systems, compilers, and similar low-level stuff. The entry barrier to system programming is high and usually goes through university. Not because you will learn some programming secrets at university, but because it will be difficult for the average person to delve into system programming without forcing themselves. And in most universities, they will simply force you to do it; you'll have to pass labs. The second type of programmers are application programmers. These guys write applications using products that system programmers have written for them. Essentially, they take ready-made bricks and build the necessary application from them. Moreover, there are many more application programmers needed than system programmers; the demand for them is higher. In short, application programming is what you most likely want to do when you think about coding. The eternal problem for beginners is choosing a programming language. I'll say right away: pick any. Python, JavaScript, Java, C#, C++, PHP – it doesn't matter. You can randomly pick one of the top ten most popular. Any of these programming languages consists of the same constructs and, in essence, solves the same tasks, namely, some actions on data. The key point you should understand is that different languages are just different tools. There's no better or worse. You wouldn't compare a hammer and a screwdriver, would you? If you need to drive a nail, you take a hammer. If you need to unscrew a couple of bolts from the lecturer's chair, you take a screwdriver. It's simple. With programming languages, it's the same. Java is good for all sorts of secure transactions where people are willing to tolerate a slightly longer program execution for the sake of security, and C++ is needed everywhere where speed and full control are required, for example, in real-time systems for controlling some combat robot. Why is that? Because Java has a garbage collector that you don't control, and if you wrote a combat robot control system in Java, you might miss a fatal blow to the head when the garbage collector suddenly decided to free up some memory. People who are not very familiar with programming often have the opinion that C++ is the best language and you should only write in it because it's complex and fast. So, if you don't write in C++, you're doing something wrong. Even my girlfriend asked me why I write in some garbage instead of C++. So, the opinion is quite popular. The answer is: because writing in C++ is difficult and expensive. If you need a simple Telegram bot for some cafe, writing it in C++ is simply absurd. Take Python and do it 20 times faster. In C++, you yourself allocate memory for your program and clean it up yourself. This is both an advantage and a disadvantage because you constantly have to think about allocated memory, and if you mess up somewhere, there will be a leak of that memory, and your program will consume all the available RAM on the computer it's running 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. C and C++: what's the difference and why are these languages given so much attention? Why am I not telling you about C#, for example? Let's start from afar. In the early seventies, most people wrote in assembler; it was difficult and slow. Then C appeared, along with which the level of abstraction significantly increased compared to assembler, where you had to keep in mind what was in which register and to do simple actions like addition, you had to write something like this. This same example in C. I'm saying this because C became a breakthrough in terms of code readability, but it was still tied to the machine you were writing for. C++ came out in the mid-eighties, a decade after C's birth. The main features were OOP, although back then no one knew what OOP would become today. OOP is one of the programming paradigms. We won't touch this topic today; I'll just say that Java is maximally class-based, a framework you must adhere to, while JavaScript, on the contrary, is multi-paradigm. References and a broad standard library, which made C++ even more abstract than C, and it could already be considered a truly high-level language. A library is someone'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 to you the rules of how you should write code. In short, another programming language on top of yours. Despite its venerable age, C++ is still alive and will be written and will be written. A small feature worth knowing is that in C++, you can write like in C because it literally grew out of C, but this is considered bad code style, and usually, no one does it. I also mentioned C# here; it's Microsoft's brainchild, very similar to Java, and it has no relation to C++ except for memory management. It's important to know about types in different languages as well. All typing can be divided into static and dynamic. C++ has static typing. To create a variable there, you must specify its type. This is necessary for optimization and fast program execution. It's very good if the program knows about all data types in advance and that they are guaranteed not to change. But in JavaScript, typing is dynamic. This means you can change the type of data of a variable right at runtime, i.e., during program execution. Besides the fact that this can lead to errors, it also reduces the program's speed because the fact that your variable is a number now doesn't guarantee that it won't become a string in the future. Phew, I hope it wasn't too boring. Give some feedback in the comments on how you like this format. And if you're still not subscribed to my Telegram for some reason, the link will be in the description. Returning to the question of choosing a language, just pick any, because at first, there will be no difference for you. You will simply get acquainted with the basic things in programming, and changing languages in the future, when you already understand what's what, will be no problem at all. If I could start from scratch, I would choose Pascal because it's good for starting. Strict typing and clear syntax. This is not just my opinion; it's the opinion of many people who teach programming in universities. We'll be honest, it's unlikely to convince you to learn Pascal, so I'll repeat myself for the third time: pick any. The choice of programming language as something important is too overrated, and the out-of-the-box capabilities of languages differ very little. Here's a program that simply outputs the text "Hello" to the console in Python. And here it is in C++. Somehow, in Python, it's more readable and more compact. But despite this, everywhere there is the possibility to use branching like If else, or exclusive or, equal to, not equal to. If admin or moderator, display "Personnel online" in the chat. Such code is constantly used in real programs. This is basic logic; a programmer should also know it. Besides this, there are loops like While and For, which will execute as long as the condition is true. Right now, I'm writing code in VS Code. Usually, code is written in IDEs; these are special programs with a bunch of useful features. This thing at the bottom is the terminal. This is 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 is written in JavaScript, and to execute a JavaScript program, you need to ask Node for it. Node is a program that executes JavaScript. If I had made the example in Python, I would ask Python to execute my code. For Java, you first need to compile the program into a separate file and only then execute it. The same for C++. Why? Because Python and JavaScript are interpreted, meaning some other program executes them, which itself converts these files into bytecode, then executes it, and itself worries about how it will be executed on different operating systems and different processors. Don't confuse bytecode with machine code. Bytecode is executed by the language interpreter. In compiled languages, the compiler does all this, just like optimization, checks, and a bunch of other processes. A 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 difficult. 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 itself. Remember how in childhood you downloaded Java so that M would run? That was needed so that your computer could execute Java code. Java is on phones, refrigerators, and PCs, all thanks to its virtual machine. If you ask me, why shouldn't Java be an interpreted language if it executes its code itself anyway? In reality, it's a bit more complicated, and the line between compiled and interpreted languages is just another abstraction. The processor will in any case execute only machine code. There are also various optimizations like JIT compilation, but that's an advanced level. For basic understanding, it's enough to know what I've told you. Well, now we will look at the code of a small program with a fairly simple functionality and try to figure out how it works. But first, let's run our program and see what it can do. We type "python3" and the file name. We are asked to enter our password. We enter the password, after which we get a response: whether our password was among the database we are searching in. I have only three lines here, but in reality, you can find very large files with passwords and check if yours is among them. Now let's look at the code. At the very top is a comment. It has no relation to the program's execution. 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 a special syntax highlighting was invented to highlight the code. Purple words are Python's keywords. "def" is the declaration of a function. If you, like me, threw math out the window in the first minute and until the end of the eleventh grade, understanding what a function is would be difficult. But now I'll explain it to you. A function is a kind of educational tool. Imagine a portal like in Rick and Morty. You give this function some data, and it transforms it and returns a result. This function takes x and returns its doubled value. Our function is called "check_string_in_file" and takes one argument. We name functions, arguments, classes, variables, constants, anything in our code ourselves, so that other people can understand what your program does. Naming a function that adds two numbers "dinosaur" is not allowed. A person reading the code should clearly understand what your program does based on its name. "with open" is needed to work with files. When we exit this code block, the file "f" will automatically close. A code block in Python is regulated by indentation, and in most languages, by these curly braces. Now we are here. Next, we open the file named "text.txt" with read permissions. It's in the same folder as our executable file. Then we assign the result of calling the function "readlines" on our file to the variable "file_content". "readlines" is a thing from Python itself; it's already in it. We just read all the data from the file into our variable and made a list out of them. A list is a data structure in Python that you can iterate over, meaning move through. Now we enter a loop that transforms strings from "file_content," thereby iterating through your strings. The code inside the loop will execute until the strings run out. The code itself trims the separators between strings and compares the current string it's on with what we passed to the function, and if it finds a match, it exits the loop, returning true. In the end, we will compare every word from the file with what we passed to our function, and only if there's a match will it return true. We've finished with the first function. Now, the "main" function. It's customary to call the entry point of our program. It no longer takes any arguments but is simply called for its side effect. Inside it, we have a variable that stores the value entered by the user. Then we call the function declared above, passing the user's string to it, and if this function returns true, we will see a message in the console that our password was found. Otherwise, we will see the opposite message. It's unlikely that the functionality of this program impressed you, 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 knowing how to program only begins with mastering some language. Next, you need to get acquainted with how the processor, memory, internet, operating system, databases work, learn a bunch of libraries, a couple of frameworks, get acquainted with tools without which you cannot work, like Git, and the most difficult thing is to learn how to design applications. Every large program consists of a bunch of nested folders and files that eventually connect to one. No one writes programs in a single file; they are divided into modules. Considering all this, there are many rules on how you should 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 about this, and smart guys love to discuss it, but you can only talk about some kind of architecture if you have solid experience in writing code and creating programs. I hope I was able to interest you in programming and you learned something interesting for yourself. Be sure to write if you liked this video format. Subscribe to my Telegram; there's a lot of good content there. And if you want to support the channel, all links are in the description. Thanks for watching. See you again. [Music]