Programming languages come in many different forms, but they all accomplish the same thing: they allow a programmer to communicate with their computer and make it do what they want it to do. At this point in our history, we rely on computers for just about everything we do, and yet many people have no idea how they actually operate! Learning a programming language not only lets you write your own programs, but it gives you a stronger understanding of the hardware that affects your everyday life. Programming builds your analytical abilities and, like learning a foreign language, it keeps your mind sharp. This article is a basic introduction to some of the concepts you will need to know in order to successfully learn a programming language.
Programming languages are divided into high- and low-level languages. High-level languages are written to be easily read and understood by programmers, while low-level languages consist of assembly languages and binary, which the CPU reads and understands. The most basic type of code a computer understands is binary. Binary is made up of strings of ones and zeroes which can be used in different combinations to make different characters. Binary is very easy for a computer to understand, because it only has to recognize two states (a one or a zero). Each 1 or 0 is called a bit, and a set of 8 bits makes a byte. One byte is enough data to represent a letter of the alphabet, or a number up to 255.
The position of a bit in a byte determines its value. From left to right, bits represent exponentially larger numbers. Programmers can string together multiple bytes to store larger amounts of data.
Below is an example of how the uppercase letter “A” would be represented in one byte of binary:
0 1 0 0 0 0 0 1
This expands out to represent the equation below:
00 + 11 + 02 + 03 + 04 + 05 + 06 + 17 = 65
When you type an uppercase letter “A” on your keyboard, your computer is actually saving a value of 65, which is interpreted graphically as the uppercase letter “A.”
However, it requires a lot of effort for a programmer to program directly in binary: it takes a lot of instruction to do even basic tasks! This is where assembly language and the high-level languages come in. In order to go from an assembly language to binary, the code is run through a program called an assembler, which translates the assembly language into the machine’s language (binary). The same process is true for high-level languages and assembly languages. In order to make your high-level language (one that programmers can read, like C++ or Java) program into assembly language, it goes through something called a compiler. Most programmers set up a development environment in a program such as Visual Studio which allows them to write and compile the code all in the same place. The benefit of this structure is that programmers don’t have to work in low-level languages like binary. C++ and other high-level languages are easy-to-read and use common words that a human could understand, even without an extensive background in programming.
One of the most basic programs is the “Hello World!” program, often used for absolute beginners. Below is an example of “Hello World!” in C++ and an assembly language. Notice how complex the assembly language is compared to C++. Even if you don’t know any C++, you could probably make a pretty good guess what the different lines of code do, while the assembly language is much more cryptic.
C++ | Assembly – x86 Windows 32 bit |
#include <iostream.h> main(){ cout << “Hello World!”; return 0; } |
.486p.model flat,STDCALLinclude win32.inc extrn MessageBoxA:PROC extrn ExitProcess:PROC.data HelloWorld db “Hello, world!”,0 msgTitle db “Hello world program”,0 .code call MessageBoxApush 0 ends |
The main challenge in learning a new programming language is the syntax. Even though they are designed to be easy to read and understand, programming languages require the user to know the correct syntax, just like learning the grammatical rules of a foreign language. A computer will read all of the information it is given exactly as it is presented, so minor things (like forgetting to close a bracket) will show up as errors.
This will work:
#include <iostream.h> main() { cout << “Hello World!”; return 0; } |
This will get an error:
#include <iostream.h> main() { cout << “Hello World!”; return 0 } |
The only difference is the lack of a semi-colon after the “return 0” line, but it is enough to stop your program from functioning.
My own experience with programming has been through game design and development. There is a much greater need for game designers to read and understand code than to necessarily be masters of programming, so I’ve taken a more everyday approach to my practice. Many of the complications I have run into are usually related to setting up a proper development environment. If you work with different libraries, it can sometimes be difficult to make sure your program files are all organized properly. In game design, it is typical to work from massive amounts of pre-written code, which you then have to make sure are all connected and communicating properly. This is known as a “game engine,” and allows game programmers to spend less time reinventing the wheel, and more time adding new features to their program.
If you keep these concepts in mind, learning to program becomes a lot easier. It takes time and effort to truly master any language, but you can start with a solid foundation by learning the basic concepts before worrying too much about complex grammar rules and syntax. Anyone who wants to learn a programming language should look at the books available in their respective field, in order to learn not just the basics but how different languages are used specifically in each field. For example, expect a software industry job to be more involved in low-level coding, while game design will typically focus on high-level coding. Probably the most popular code for beginners is C++, because it is particularly easy to read and has many attributes found in most popular programming languages. For game designers, I would recommend the second edition of Starting Out with Games and Graphics in C++ by Tony Gaddis. It begins with a well-rounded introduction to C++, followed by an introduction to a simple game engine, the App Game Development Kit.