Source Code

Share

What is Source Code?

Source code is (normally) a type of text code written by a programmer or developer that describes the algorithm to be executed by a computer program, or controls the program by configuring it somehow or by describing some data used by it.

The code that the CPU executes is called machine code and it's very difficult for a human to program in. In practical terms, machine code are electrical currents running through circuits in the the CPU that control its transistors. In abstract terms, they're bits, where 0 could mean a circuit has voltage, and 1 could mean a circuit doesn't have voltage. CPUs are designed to be controlled by packs of bits (currents) that go through with. At a higher level, this means that a specific set of bits (currents) trigger a CPU operation. This is called an opcode (operation code). Today, these opcodes are usually at least one byte (8 bits) of length. This could mean, for example, that there would be 256 opcodes, from 0 to 255, and a programmer would have to somehow tell the CPU what's the number of the opcode it should execute.

One of the first types of source code was assembly, which abstracted these opcodes into text characters. With assembly, you would write mov, for example, for a move operation, and a computer program called an assembler would translate this text into the machine code equivalent. Assembly was just a text representation of the machine code, so it was exactly how the CPU executed programs. The average programmer doesn't program assembly.

The next level would be to use a compiler. In this case, you write the logic of the program in a high-level programming language, like C, and the compiler takes care of translating concepts that only exist in the C programming language, like if, else, for, variables, pointers, etc., into the machine code equivalent. For example, in C, you would write statements that only execute conditionally like this:

if(x > 10) {
    x = 10;
}

Machine code doesn't have the concept of blocks of statements {...}. Instead, there would be an instruction to "skip" the code that says x = 10 by jumping to (jmp in assembly) to whatever line comes after the skipped part.

Above this level we have data-oriented programming. In this case, we have a complex algorithm that does different things based on some piece of data, but instead of getting the data from an user who inputs an application in a text box, for example, the data would be files written by a developer in some complex code that the application can understand. One example of this would be web browsers, which interpret a source code in the Hyper Text Markup Language (HTML) to render web pages.

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>This shows on the tabs</title>
<h1>This is a heading</h1>
<p>This is a paragraph.

Above we have an example of HTML source code that could be read by a web browser to render a simple web page.

How is Source Code Written?

Source code can be written by anime plain text editor, like Notepad that comes installed with Windows. But there are specialized editors for editing source code that will make your life easier, like Notepad++ and Visual Studio Code.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *