What is code?

Knowledge Lighthouse
57 followers
37 Video Views·Oct 27, 2022
People that can code seem like they have superpowers, but what is code exactly? It's
all around us in our computers, phones, and in things like drones and self-driving cars.
Movies and TV shows make it look like flying ones and zeros or weird green characters that
look like brain. This comes from the early days of programming, 30 or 40 years ago, when it was
much more difficult and you really did have to know a lot about the internals of a computer.
Today, it's not as complicated as it looks, and by the end of this video,
you'll even know how to read some code. There are thousands of programming languages, but
all of them are a way to tell the computer what to do. So let's say you're unlocking your phone
with a numeric password. There are two possible outcomes here. Either you'll get the password
right and your phone will unlock, or you'll get it wrong and your phone will ask you to try again.
In code, this type of logic can be expressed in what's called an if statement, which,
depending on the language, might look something like this. If you've never coded before,
all of these weird characters might look strange to you, but let me show you how to read this.
Computer code is usually interpreted one line at a time, so we can start at the top. First,
there's the keyword if, and then inside of the parentheses, there's a condition it's testing.
That condition is checked while the code is running, and it can be either true or false.
We'll come back to that in a second. Here, we have two words, input and password. These are
what are called variables, and they store all types of information like numbers, words, a photo,
and more. And, you can name your variables whatever you want. I've named these two variables
input and password because I want to compare what the user typed in, the input, to the password
that's stored on the phone. The two equal signs means that we're comparing these two variables
to see if they're the same. So, we can read this as if the input is equal to the stored password,
then execute this next bit of code inside these two matching curly braces. And, inside there,
there is a line of code that will unlock the phone. But, what if the input doesn't equal the
password? Then, the if statement will evaluate the false, and it will skip over the first set
of curly braces and drop down to the else statement, and then execute whatever code
is inside its curly braces. So, to summarize, we're saying if the user's input matches the
stored password, unlock the phone. Otherwise, tell them to try again. And, that's it. You just
learned how to read a little bit of code. Of course, there are lots more coding concepts,
but if statements like this pop up in almost every website and app in the world. Like I said before,
that's just a small piece of a program. You can imagine how lots more if statements and other
pieces of logic can be put together to make a full app. It's sort of like the rules of grammar,
and how words can be put together to form sentences, and sentences can make paragraphs,
and so on. So, who writes code, and how do they do it? The people that write code go by many names.
Sometimes they're called programmers, or developers, or coders, and they usually write
code on a computer using special apps. Sometimes these apps are called text editors, or IDEs,
which means integrated development environment. If the code is a simple website, usually it can
just be uploaded straight from their computer to a web hosting service, and it'll work fine.
If the code is an app that's meant to run on a Windows or Mac computer, or perhaps an iOS or
Android device, then the code needs to be compiled. That means that the human readable code that we
just looked at is converted into the simpler instructions that the computer will understand,
like ones and zeros. This is way more complicated than what most people are able to read,
which is why we have programming languages to make it simpler. There are a lot of ways to learn
how to code, but anyone can do it. You don't even need a college degree. If you want to learn how
to code and build apps and websites, I recommend you check out Treehouse. I'm Nick Pettit, one of
the teachers there, and it's an online school where you can go from knowing nothing about coding,
to landing your first job building websites and apps. And now, the next time you see a movie with
code in it, you'll know that it's actually not that difficult.
