How to Use Basic Coding Commands
What are the basic commands used in computer programming languages?
Do you have any friends or family that program as a hobby or as a job? Have you ever looked over the shoulder of someone writing code and wondered, “How the heck do they make sense of all that gibberish?” One of the most frequent questions I’m asked is how do you learn programming.
I’m going to demystify programming by popping the hood and showing you that, without even knowing it, you may already know some of the basics.
Programs are simply a set of instructions that people give to computers to perform a task. Even if you hate computers, or think that you don’t know anything about programming, I’m sure you’ve used and written a handful of your own programs without even knowing it. If you’ve ever followed a recipe for cooking, put together something from Ikea, or explained to someone how to get to your house, you’ve written a program. In other words, you’ve followed a set of instructions someone else gave you, or you wrote instructions, for someone else.
Decision Making
Almost every programming language has the following statements in common: IF, THEN, ELSE, FOR, and WHILE. These commands are used to make decisions within a program and perform actions. Let’s look at IF and THEN. Say you’re out of milk and you want some cereal. In the form of a program that would look like “IF you need milk THEN you need to go to the store.” Writing programs use IFs and THENs to make decisions just how it sounds: if something happens then perform the following task.
Next let’s take a look at ELSE. ELSE would be like saying “otherwise.” For example IF you are out of milk THEN go to the store ELSE (otherwise) stay at home and watch Netflix. See it’s pretty easy to understand, right? Think of how many times you use that sort of logic in your head while driving, having conversations, going to the store, or making every decision. All can be formed into IF this happens, THEN do this, ELSE do that.
The next part of explaining coding has to do with loops. Loops are just fancy ways of waiting for something or performing an action a certain number of times. This is where FOR and WHILE come into play. Think of baking a cake: you have to put the cake in the oven FOR 20 minutes. You might use WHILE in a similar way (for example, WHILE the cake is baking keep the oven on).
These five basic words can be found in just about every programming language out there, and they all operate pretty similarly.
Storing Types of Data
Now that we know how programs make decisions, let’s take a look at what they do with that information, and where they get it from. Information in a computer program is stored in something called a “variable” which might be shortened down into just “var.” A variable is just something that stores information.
Think of your grocery list as a variable. It contains information about what you need from the store: avocados needed for your guacamole, , the name of your favorite chips, or what isle that can of soup is on. It simply contains information. Computers interpret data in a couple of ways, but on a basic level, they look at information as a “Number,” as just text known as a “String” (think of a string of letters), or a “List” (which can have numbers or text). Now different programming languages have a number of different ways they break these down even more, but for now that’s as deep as we’ll go.
If we were to write a quick program about you, we would need certain pieces of information. For example, if your name is Fred we might store that piece of information in the variable Name. If you’re 32, we might store that number in the variable Age. And if you have blue eyes, we might store that in the variable “Eye Color.” Variables can store any information, and can be named whatever you want. This makes it a lot easier to read and write programs.
Operators
Now that we’ve covered the decision making process, and how to store information, let’s look at how programs actually use these items. Programs make use of operators, such as greater than, less than, equal to, and not equal to, in order to compare data and variables.
An easy way of thinking about this would be to look at your thermostat in your house. Say you want your house to stay between 70 and 80 degrees. You would need three variables: the high temperature (80 degrees), the low temperature (70 degrees), and the house temperature.
The program would look like this: IF the inside temperature is less than 70 degrees (our low temperature) THEN turn on the heater. IF the inside temperature is greater than 80 degrees (our high temperature) THEN turn on the AC. This is a really simple example of how you might use a program.
What makes programs like this extremely powerful is that computers are really good about making simple decisions really quickly. For example, if you wrote a program to find the average high temperature over the course of a year, the computer could solve it before you even pulled out your calculator. This makes many things much easier, and it is why you can find programs running everywhere from your thermostat to your microwave, remote control, video game, garage door opener, you name it.
All of these programs and conveniences have the same simple building blocks. Now that you’re hopefully thinking, “Wow, Tech Talker, programming isn’t as hard as I thought,” I recommend you check out CodeAcademy.com, edx.org, lynda.com, or coursera.org and learn more about programming. With just a couple of hours of practice you can make some pretty cool programs, and even if you’re not trying to quit your day job, knowing some programming basics will be useful in an increasingly technological world.
Here’s a real program written in python. See if you understand it.
High_Temperature=80
Low_Temperature=70
House_Temperature=90
If House_Temperature>High_Temperature:
print(‘Cooling down house’)
Else House_Temperature<Low_Temperature:
print(‘Heating up house’)
Can you predict what this program does? Comment on my Facebook page or in the comment section below if you think you know what this means.
Be sure to check out all my earlier episodes at quickanddirtytips tech-talker. And if you have further questions about this podcast or want to make a suggestion for a future episode, post them on Facebook QDTtechtalker.
Until next time, I’m the Tech Talker, keeping technology simple!