Placeholder Image

字幕表 動画を再生する

  • Welcome to Introduction To Programming. My name is Steven

  • And my name is Sean.

  • Over the next 90 minutes, we'll be taking you through this series consisting of 21 different

  • segments that hope to cover the basics of computer programming, which can apply to any

  • and all programming languages you might want to learn. We'll be starting with the simplest

  • question of what is programming, and from there will be working our way up as we talk

  • about common features of computer science such as loops and arrays. We'll discuss

  • how to read and write code, debug code you've written, some strategies to help plan out

  • your code, and much, much more. The complete list of topics that are going to be covered

  • in this lecture-style video are shown on the screen now. Additionally, there will be time-stamps

  • in the description, so feel free to skip around if you are already proficient in some areas

  • of computer science, or just want to know about a specific topic we will be covering.

  • Hopefully, by the end of the series, you'll have a basic understanding of what computer

  • science is, along with an armory of useful skills that will help you unravel whichever

  • programming language you decide to learn first.

  • We'll only be covering the major key points that apply to all programming languages, so

  • we'll be shying away from topics such as object-oriented coding and command line navigation,

  • as those are things which are language-specific. Additionally, there will be no software required

  • for you to download in order to follow along with this tutorial as we won't be writing

  • any code to keep things simple and concentrated. This video is meant for those who are interested

  • in computer science and programming but have no idea where to start and have little to

  • no background information on coding, and so if that sounds like you, then strap Sean and

  • I work our way through the wacky world of computer science, starting with the biggest

  • question probably on your mind, which is what even is programming?

  • Well, the dictionary defines it as the process of preparing an instructional program for

  • a device, but that's a really confusing definition, so in layman's terms what exactly

  • does that mean? Essentially, it is attempting to get a computer to complete a specific task

  • without making mistakes.

  • Imagine this, for example: you want your less-than-intelligent friend to build a lego set, except he has

  • lost the instructions and can only build based on your command. Remember though, your friend

  • is far from competent, and so If they are not given very specific instructions on how

  • to build the set, there are many mistakes he could make. If he thinks like a computer,

  • then if there is even one piece that you have not told him specifically where to place and

  • how to place it, the entire lego set will be ruined and he will be left to suffer a

  • complete mental breakdown causing the whole goal of the project to be corrupted. Giving

  • instructions to your friend is very similar to how programmers code. Instead of a less-than-intelligent

  • friend, you have a less-than-intelligent computer, and instead of instructions on how to build

  • a lego set, we are feeding it information on how to complete a program like a game or

  • web application. An important thing to note is that comptuers are actually very dumb.

  • We build them up to be this super sophisticated piece of technology, when in actuality, a

  • computer's main functionality comes from how we manipulate it to serve our needs.

  • Now, programming isn't as simple as giving your friend instructions since in a programmers

  • case, the computer doesn't speak the same language as you, the computer only understands

  • machine code, which is a numerical language known as binary that is designed so that the

  • computer can quickly read it and carry out its instructions. Every instruction fed to

  • the computer is converted into a string of 1's and 0's and then interpreted by the

  • computer to carry out a task.

  • Going back to the lego example, this process would be like if he was not only less-than-intelligent,

  • but to make matters worse, he could not understand english and only speaks in mandarin chinese.

  • In order to speak with him, you have to convert the instructions that you understand in english

  • into the language that your friend understands. This process is essentially what you must

  • do for your computer in order to make it understand the instructions you give it.

  • The big difference between the two examples, however, is that it is very difficult for

  • people to understand machine code and binary. Directly translating what you want the computer

  • to do into machine code is extremely difficult, in fact almost impossible, and would take

  • a very long time to do if you could. Each program is composed of millions upon millions

  • of those 1's and 0's, so how, exactly, are we supposed to translate our instructions

  • into machine code?

  • This is where programming languages come into play. Programming languages are fundamentally

  • a middle man for translating a program into machine code. These languages are much easier

  • for humans to learn than machine code, and are thus very useful for programmers. Going

  • back to our lego example, a programming language would be sort of like an interpreter, that's

  • able to take the instructions you give them in english, and translate them into instructions

  • your non-english speaking friend can understand. This makes programming languages extremely

  • useful and the backbone of almost any good program. Think of programming languages as

  • not english, and not machine code, but somewhere in the middle.

  • There are many different programming languages out there that each have their own unique

  • uses. Languages such as Python and Java act as general purpose languages that can perform

  • a variety of computational tasks, while RobotC or HTML/CSS are languages designed for more

  • specific purposes such as moving a robot or constructing a website. Languages can also

  • vary in how powerful they are. For instance, JavaScript is a scripting language that is

  • designed for smaller tasks while java or python can carry out much more computationally taxing

  • processes.

  • We measure a programming language's power, or level, by how similar it is to machine

  • code, the series of 0's and 1's we talked about earlier. Low-level programming languages

  • such as assembly or C are closer to binary than a high-level programming language such

  • as Java or python.

  • The basic idea is that the lower the level of your programming language, the more your

  • code will resemble what the machine can interpret as instructions. Aside from the different

  • purposes that each language fulfills, choosing a programming language typically comes down

  • to a matter of preference, as there are usually many languages that accomplish similar tasks.

  • Try different languages, and decide which one's rules, interface, and level of simplification

  • you like best.

  • So now that we know what programming is, how do we actually write code? It's not like

  • we can simply type words into a text document and automatically assume that the computer

  • can translate it into machine code, read it, and carry out a task like opening up a browser.

  • And additionally, we can't just write down rubbish in certain programming languages mentioned

  • in the previous episode and expect the computer to understand. So how are we supposed to write

  • code then?

  • Well, the answer is with an IDE. An IDE, which stands for Integrated Development Environment,

  • allows the facilitation of code by a computer. IDE's provide a graphic interface on your

  • computer in which the programmer can easily write, run, and debug code without having

  • to worry about problems with compilation or interpretation of the program. Think of an

  • IDE as any other program on your computer such as a game, a browser, or even the file

  • explorer, except we'll be using it to write code. IDE's are able to turn your code into

  • machine code and run it through the computer to produce results.

  • In addition to providing a place for programmers to develop their code, IDE's provide some

  • extremely useful tools for programmers to ease the job of writing code, such as built-in

  • error checking because as we'll talk about later; code doesn't always run correctly,

  • auto-fill in for frequently used words or phrases, and project hierarchy which will

  • help you organize and manipulate the files within your project. Back in the olden-days,

  • before IDE's, code used to be written on punch cards and then fed into computers which

  • would take hours and cause a lot of pain. IDE's nowadays act as a sort of fast-track

  • to writing code and make things a whole lot easier for programmers. An example of a specific

  • IDE can be seen on your screen now. In the center you can see the program that is currently

  • being written, and right below it the console, which can print out useful information for

  • the programmer. This specific IDE is used to write java code. IDE's are extremely

  • powerful and will be used in almost 100% of your programming projects.

  • So through these IDE's we are finally able to write and compile code smoothly without

  • worrying about the computer not being able to understand it. The next problem we run

  • into then becomes how do we write this code in the IDE, because it's not like we can

  • just type random words from a certain programming language and expect the compiler to understand

  • it. This is where a programming language's syntax comes into play.

  • Now, just as if you were learning a real language, learning a computer language can be very similar.

  • Some have different styles that may seem odd, some may make you use abstract or weird concepts

  • which may be confusing, and like all languages, programming languages have a set of rules

  • that you must follow when writing code in that language, and at the forefront of those

  • rules is grammar. Programming grammar is referred to as syntax and is very similar to real-world

  • grammar. Each programming language has its own syntax, or rules, that you have to follow

  • to a tee if you want your program to run correctly, just as if you were speaking in real life.

  • These can be things such as how you type out certain functions, what you put at the end

  • of a line of code, and how you set up certain functions. Each language is unique in its

  • syntax, and while some may share similar rules, all will have some quirk which makes it stand

  • out from the rest. Syntax is something that catches a lot of people off guard, since many

  • expect every programming language to follow the same set of rules, but as we spoke about

  • in the last segment, because each language is specialized for a specific task, each needs

  • its own set of rules to function. Breaking or disregarding these rules will result in

  • an error, just how breaking or disregarding rules in real life will result in an unintended

  • message.

  • As an example. If we wanted to do something simple such as initialize a variable, which

  • is something we haven't covered yet but the example is still relevant. In java, you'll

  • notice we have to specify what type of variable we are defining in this case an integer, and

  • also add a semi-colon after the statement. In python, we don't even need to define

  • that we are trying to create a variable and just have to type what we want to create,

  • and in javascript, we just specify we are making a variable, but do not include what

  • type of variable we want to make. Even in this simple example you can see how much syntax

  • matters when learning a new language since while the goal of our program remained the

  • same, define an integer with value three, all the programming language shown took different

  • approaches. All these languages require that you follow this syntax because remember, computers

  • are extremely dumb, if you forget one semicolon or misplace a character, the entire program

  • will not run and send you back a syntax error, which is something we will talk about later.

  • Think of this as if you forget a comma in a sentence and the entire context of what

  • you are trying to say get misinterpreted. For example, in the sentencelet's eat,

  • grandma”. If you were to forget that comma, while it may seem like a small mistake, it

  • changes the entire context of the sentence, making it sound like you're about to eat

  • your grandma. The same rules follow for programming, if you forget a semicolon, the entire context

  • of your program could be corrupted and misinterpreted.

  • Now another thing which makes IDE's so useful is that they will let you know if and when

  • there are syntax errors in your code. Syntax errors of course being parts of your code

  • which do not follow the rules we talked about previously. The IDE will tell you where in

  • your code the error is, and also won't let you run your program until the error has been

  • fixed. Because of how important syntax is to writing code and learning a new language,

  • it's recommended that you learn the rules and syntax of a language before beginning

  • to write complex programs in that language. Most of the rules are tedious to learn but

  • easy to master and as soon as you can do that, you'll be able to easily identify syntax

  • errors and take care of them easily.

  • That covers the basic gist of syntax and programming rules, so now that we know HOW to write code,

  • and WHERE to write code, we next need to cover what happens after we have typed out our program

  • and run our code. Because writing a piece of code for a game or for a database is cool

  • and all, but after the computer interprets the program, how will we know what's happening,

  • and whether it is working or not? Well, programmers do this by looking at the console. The console

  • is a text interface within the computer that us programmers can use for a variety of different

  • purposes. If you remember, a short while ago we showed a picture of a basic IDE, and one

  • of the main parts of that picture was the console.

  • The main use of the console is to output text from the program. This is usually done using

  • a print statement. A print statement is a command that does exactly what it sounds like:

  • it prints text to the console. This print statement is the first piece of ACTUAL CODE

  • we've talked about in this series, and it's about as simple as it gets. The print statement,

  • despite its simplicity, is one of the most important functions in programming and exists

  • in some form in just about every programming language.

  • The most basic thing you can ask the print statement to do is just simply make it say

  • something. This is done by instructing the console to print, and then include whatever

  • you want to be printed inside the parentheses. For example, in python, the segment of code

  • print(“Hello World”) will cause a message readinghello worldto appear onto the

  • console. Pretty neat.

  • The print statement is also vital for viewing and interpreting the computer's output from

  • a program. For instance, if you tell a computer to run a simple calculation, for instance

  • to determine what 4+3 is, it will run the program internally and compute an answer.

  • However, what is the purpose of having the computer run this program if you will not

  • be able to tell what the result is? Instead of simply telling the computer to perform

  • this calculation, instruct the computer to print the output of the program to the console,

  • and upon the program's completion, 7 will appear on the console. As you can see, the

  • console allows us to easily print information out to the developer for a variety of uses.

  • It is important to note that the print statement varies depending on the programming language

  • being used. For example, in Java there are multiple versions of the print statement depending

  • upon whether you would like a line break after the printed text, and specialized print statements

  • which make your code more efficient. Also, the general syntax of using a print statement

  • and certain nuances of its function can change between languages. However, you can generally

  • rely on it carrying out the same overall function, as it is a foundational statement for programming

  • in general. So print statements, they print information out to the console for the developer

  • to use, nice.

  • All of its functionality makes the print statement, along with the console, a very useful developer

  • tool. However, it is important to remember that that is all it is: a developer tool.

  • The console is not really meant to be viewed by the end user of your program. It tends

  • to be hidden away behind the scenes, and other methods of displaying information such as

  • displaying text, graphics, or images are used to convey information to the user instead.

  • Think of it like this, when you're using your phone, you see the console in none of

  • the programs you use. So while you can use the console to give yourself information about

  • how your program is performing, don't try to implement it in the final product because

  • it fundamentally just isn't meant for that. Overall, remember to use the console to its

  • fullest extent when writing and fixing problems in your programs, as it is a great tool to

  • use to tell how your program is performing behind the scenes.

  • So now that we know a whole bunch of information about programming languages and how and where

  • to write them, along with the print statement under our belts, let's go over some intuitive

  • things the computer can do all by itself, without you having to tell it how to. More

  • specifically, we'll be covering basic number mathematics as well as string math

  • Starting off with basic mathematics, the computer already knows how to do simple arithmetic.

  • This includes addition, subtraction, multiplication, and division, all of which are represented

  • by the symbols shown on the screen now. In any IDE that you may install, you'll be

  • able to print out the answer to simple math problems using the print statement, which

  • may seem counter-intuitive because why would you use the computer to do math when you have

  • a perfectly good calculator on your phone, but you have to remember that computers are

  • dumb, and anything we want a computer to do we have to build up from scratch. Basic arithmetic,

  • while simple, helps out in almost any program you may write. For example, if we wanted to

  • build a basic calculator app, we'd need to utilize this functionality in order to

  • correctly display the answer to an arithmetic problem when our user tries to add, subtract,

  • multiply, or divide two numbers.

  • Now in addition to the 4 basic math equations, most programming languages include an additional

  • operator known as modulus. If this is your first time hearing this word, don't worry,