How Coding Works

Understanding how coding works starts with a silicon chip etched with millions or billions of tiny transistors. These act as switches, and they only have two states, on and off. These represent 0’s and 1’s, the building blocks of binary code or machine language.

We have gone from early 8 bit systems which only handled 256 numbers at a time to 64 bit systems with 264 numbers. It would take an extreme amount of time and a lot of unnecessary effort to put together a program based on the binary code that your computer uses especially with 1.844×1019 ones and zeroes! We need a better way to communicate with the machine than binary code in order to make efficient programs.

The Legacy of Binary: Machine Language

How programming works starts back to Binary and Machine Language

At the heart of the exchange between English and your computer is binary code. Simply put, rather than having ten digits to represent a number, we have two: 0 and 1. Each digit is one bit, and eight bits is called a byte. A byte is equal to the data needed to store one letter in this introduction. Having only two digits results in long numbers to represent even small values. Early 8 bit computers could only add and subtract 28 or 256 numbers at a time. The range was 00000000 to 11111111, or 0 to 255. This meant that adding and subtracting large numbers took long amounts of time as any number over 255 required a minimum of two calculations to process. Processors were also much slower, making these calculations slow and occupying a lot of available memory.

We will discuss low level programming languages, which were designed with these limitations in mind, and later high level languages developed after processors had gone from 8 through 32 and now 64 bits. Extremely large calculations can now be done in one operation, and the number of calculations per second is tied to the speed of your processor at billions of calculations per second. New high level languages can take advantage of this efficiency, as making the conversion from English and large decimal numbers to the 1s and 0s that make up machine code takes far less time today. Setting up a calculation in the 1950s could require hours; today, the same calculations happen much faster than we blink. Despite these advances, code must still be converted into binary or machine language in order to operate.

How a Coding Language Works

Person coding on the computer

In order for a computer to make sense of what we want it to do, we use a programming language. There are 3 steps from our code to finished product:

  • We write a program using the programming language syntax
  • The program is turned into a form of machine language that is specific to the operating system 
  • The program is executed, and interacts in machine language with the operating system or processor. 

For developing programs, there thousands of different languages but only 10-15 commonly used. Some are designed specifically for interfacing with the operating system or processor, some are designed to be used for science, others for business, and still others for ease of use or portability. Another class of languages is designed specifically for Web applications. In Web scripting languages such as HTML and XML, the code is directly interpreted by the browser. The browser itself includes code specifically designed to do something called parse the code. Parse means look for special instructions or tags that tell the browser how to behave.

How High and Low Level Languages Work

There are two types of programming languages: high level languages, which closely resemble English in their construction, and low-level languages, which are closer to machine code. High-level languages are more popular because of the fact that they are easier to write; however, low-level languages are often more powerful. Most of today’s popular languages are high-level with the possible exception of C, which is considered to be a low-level language.

A programming language has a set of commands that tell the compiler how to handle certain things—for example, in Python the command ‘print’ tells the compiler to put data on the screen. 

But the computer itself doesn’t understand the command or anything that comes after it so the compiler uses the command print to create machine code. It says anything after should be stored in memory, then at the appropriate time sent to the display. 

A programming language also has its syntax, and it is what defines a language’s look and style. For instance, a C program    uses a set of special keywords, begins and ends each section with { and }, ending each line with a semicolon. Newer languages use fewer symbols and new lines begin with the Enter key so spacing is important to keep a program organized. 

Further Understanding of Programming Code

further-understanding-of-programming-code

All languages have their own syntax, and their own conventions, but what is common to all of them is they all have an algorithm, or problem to solve. Web pages make text and scripting available. Scripts can be used to solve multiple problems whether it be reporting an error or taking a username and password. In a standard programming language, the algorithm is the reason why we wrote the program in the first place. Functions in a program can also have their own algorithms which are just parts of the main problem broken down into smaller chunks. A main program without functions can become large and difficult to maintain. Repetitive sections of code are good candidates to become functions. Also, sections that change frequently are easier to edit if they are divided from the main program. 

Putting it into Code and how it works

putting-it-into-code-and-how-it-works-copyFrequently, the first program written in any language is the “Hello World” program which is a simple program designed to display those words on the screen. Here is an example in C syntax:

 

#import 
int main(char [] args) {
printf (“Hello, World”);
return(0);
}

This is a low-level language, so it has short commands and more punctuation. HTML on the other hand uses tags to instruct the browser:

Hello, Community!

This prints a nice “Hello, Community!” message in larger text. The tags containing the slashes close the tag, much like a ) closes a (. Python is even simpler, with near English syntax:

print (‘Hello, World!’)

An example of a function is shown below. We use the multiply () function to perform the math. If we decide to change how we multiply in the future, we don’t have to change our main program.

#import 
int multiply(int a, int b) { // the function
int c = a * b;
return(c);
}
int main(char[] args) { // main function
int x = 10;
int y = 2;
int z = multiply(x, y); //we use the function to do our math
printf(“The number is %d”, z);
return(0);
}

Moving Forward Benefits

Now that we have explored how coding works, you have a basic understanding of how the machine can understand what we tell it. As we move through further coding topics, we will apply this knowledge to the ideas there. We understand that each page, script, and app has a problem to be solved. In addition, it also has a means by which it is interpreted by software so that it can be converted into machine language. From there, the script or application creates a path for communication via code from the user to the machine and back. Go our next page about the benefits of learning code.

FOLLOW US ON: