This post originally appeared on Fullstack Academy's blog.
This is the first of a two-part introductory series on coding. Today we’ll review the basics of programming, including data types, variables, functions, and more. Next week, we’ll look at what it’s like to be a professional programmer.
To the budding developer, writing computer code can seem like a foreign language—which makes sense, because that’s exactly what it is.
What these words are, and the order in which you use them, differ among the programming languages. At the core of each language, though, are the same basic components and concepts.
Why Learning the Basics of Programming Is Important
Learning the fundamentals of a programming language is the first place any aspiring developer should start because those concepts are transferable to any programming language—and essential to all of them, software developer Vinicius Brasil says.
Whatever programming language you decide to learn, there will be an awful lot of new terminology and concepts to digest. This can all get a bit overwhelming if you aren’t already familiar with the basics of how computer science works in general, says developer Mikke Goes. “After learning Computer Science basics, you’ll have a solid understanding about what computers can do for you,” Goes writes. “You’ll also learn coding a lot faster, since you’ll already be familiar with most of the technical terminology you hear when you’re learning programming.”
This last point is essential. At the end of the day, you probably aren’t going to learn just one programming language during your entire career. Odds are, you’re going to have to learn several, one after the other.
Adam Wulf, founder of Milestone Made, believes changing tech stacks is inevitable. “Right now, I’m of the mind that you should plan to learn essentially brand new technology stacks every ~4 years,” he writes. That means your career will depend on your ability to learn new languages quickly, which is facilitated by a solid understanding of programming’s underlying concepts.
Coding Concepts That Aspiring Developers Need to Know
Lines of computer code might seem completely indecipherable to you right now but if you can understand the following key concepts, you’ll soon be able to start making sense of specific programming languages.
The Flow of Data
Programming is all about the flow of data. A programmer has data that they can feed into a program. The program has its own data that it can use to interpret the input data. All of this data can be combined to represent ideas and provide use to both the program and the user.
In programming, data is usually represented by what we call data types, which can include words, numbers, and other kinds of complex data.
Data types can be grouped into three buckets, says programmer Greg Bogdan:
- The first are data types that manipulate text, called strings. These are the most commonly used data type in almost every programming language.
- The second bucket contains numerical data for calculations or algorithms.
- The third bucket contains all other forms of data, like Boolean values and null values.
Data is essential, but a program can only use that data if it knows how to ask for it and what to do with it when it receives it. This is why we declare variables at the start of the program, says Richard Holowczak, associate professor of computer information systems at Baruch College in New York. “In order to use a variable within a program, the compiler needs to know in advance the type of data that will be stored in it.”
Declaring a variable simply means giving a name to a piece of data. Once you’ve named it, you can refer to that data again as many times as you want.
There are two reasons you name your data, says programmer Isaac Lyman. First, you don’t know what the data is before it is put in. Computer programs aren’t smart enough to work out that, say, a date is a date unless you define it. Second, you don’t want the program to forget what the data means later when you need to draw on it.
It’s important to note that variables do not hold data, says Samer Buna, curator of jsComplete.com. Variables just point to the data, which is held in the computer’s memory.
Once you have data and have named that data as variables, your program needs rules and instructions to allow it to make choices and execute commands. This is done with control structures.
Think of control structures as bouncers at a bar. The bouncer (control structure) is instructed not to let anyone in under the age of 21. They check each ID and if the birthday is before a certain date, that person is allowed into the bar. If the birthday is after the required date, the bouncer does not allow that person in the bar.
The importance of control structures is often lost on new programmers, says developer Philip Brown. But they are a fundamental concept, one that allows you to dictate how your code runs under different conditions or until a certain condition is met.
In order to build something, you’re going to have to give your program instructions, and lots of them—but if you’ll be asking the computer to run through the same steps over and over, writing the same dozen instructions out would get incredibly repetitive.
Enter: Functions, a way of collecting commonly used instructions and giving them a name that you can call back to. Rather than write all of the instructions every time, you can simply use the name of the function instead, and the instructions contained within that function will execute on their own.
MakeUseOf’s Ben Stegner notes that you can use functions to achieve a huge number of things, including:
- Encapsulating code without having to know the code inside.
- Dividing code into segments so multiple developers can work on it.
- Reusing code.
- Making it easier to test and debug.
In fact, it is possible to create entire software applications with functions alone, says Beanz’s Tim Slavin. There are even entire programming languages that primarily use functions, aptly named “functional programming languages.”
The final core programming concept that you need to know is syntax. In technical terms, syntax is the order that certain predefined control structures, variables, and keywords are allowed to be written in. This order defines the expected result of the computer reading and executing the code.
To simplify this concept, you can think of coding syntax just the same as you would think of syntax in the English language. The order in which you write code is very important. Write it in the wrong order and—just as with English—the meaning of what you’re saying can change drastically.
Unlike English, however, noticing syntactic mistakes in code isn’t that easy. They are the most troublesome of all errors, says Matt Adesanya, CTO of Workforce Group, because a program will typically run with syntactic errors present. It just won’t produce the right output.
Java developer Trevor Page believes syntax is probably the toughest hurdle for new programmers to overcome. But it gets easier, and for a couple of reasons. First, the more code you see, the better you’ll get at spotting syntactic errors. Second, developers have created Integrated Development Environments (IDEs) that can detect faulty syntax just as spell check does on Microsoft Word.