1. Home
  2. Explore
  3. Computer Science
  4. Introduction to Programming Languages

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Introduction to Programming Languages

Programming Languages: How Humans Communicate with Computers

A computer can perform calculations, store information, display images, and run applications, but it cannot decide what to do without instructions. A programming language provides a structured way for people to give those instructions to computers and other digital devices.

This lesson explains what programming languages are, why they are needed, how they have evolved through five generations, and how language translators convert human-readable code into instructions a computer can execute.

What Is a Programming Language?

Human beings communicate using languages such as English, Spanish, Hindi, or German. These languages allow people to express ideas, ask questions, and give instructions.

Computers also need a language for communication. However, a computer does not naturally understand ordinary human languages. It works with electrical signals and processes instructions in a special form. A programming language is the system people use to communicate instructions to a computer.

A programming language is a vocabulary and set of grammatical rules used to instruct a computer or computing device to perform a specific task.

Each programming language has:

  • A particular collection of words, called keywords
  • Rules for arranging those words
  • A special structure, called syntax
  • Meanings associated with correctly written instructions

For example, a programming language can contain instructions for displaying text, calculating numbers, storing data, or making decisions.

Algorithms and Programming Instructions

A computer cannot complete a task independently unless it receives a sequence of instructions. An algorithm is a set of rules or ordered steps for completing a specific task.

For example, making a cup of tea can be described as an algorithm:

  1. Boil water.
  2. Place tea in a cup.
  3. Pour in the hot water.
  4. Allow the tea to steep.
  5. Add other ingredients if needed.

In computing, an algorithm describes the logic of solving a problem. A programming language is used to express that algorithm in a form that can eventually be translated into instructions understood by the computer.

Thus, the algorithm explains what steps are needed, while the programming language provides a formal way to write those steps.

An algorithm is an ordered sequence of instructions for performing a specific task.

Syntax and Semantics

Programming languages, like natural languages, have rules. In English, grammar determines how words are pronounced, written, and arranged into sentences. Punctuation marks, articles, and sentence structure also contribute to correct communication.

Programming languages have two important aspects: syntax and semantics.

Syntax

Syntax is the structure or format required for writing a valid instruction.

In English, syntax includes:

  • The order of words in a sentence
  • Correct spelling and pronunciation
  • Punctuation
  • Grammatical structure

In a programming language, syntax determines how commands, variables, symbols, and other elements must be arranged.

If the syntax is incorrect, the computer may not understand the instruction. For example, a programming language may require a particular symbol at the end of a statement. Leaving out that symbol can cause an error, even if the intended meaning is clear to a human reader.

Semantics

Semantics refers to the meaning of an instruction.

A statement can have correct syntax but still produce an unintended result if its meaning is incorrect. Syntax answers the question, “Is this instruction written in the correct form?” Semantics answers, “What does this correctly formed instruction mean?”

The relationship can be summarized as follows:

  • Syntax: The structure of an instruction
  • Semantics: The meaning or effect of that instruction

A computer needs both. The instruction must be written in the correct form, and that instruction must have a meaning that the computer can carry out.

Syntax controls how a program is written; semantics controls what the program means.

Think About It

If a sentence follows all the grammatical rules but expresses an incorrect idea, is the problem with its syntax or its semantics? The same distinction applies to programming instructions.

How Computers Represent Instructions

Computers are electronic devices. At the most basic level, they respond to electrical signals.

Two basic signal states are used:

  • A high-voltage signal is represented by 111
  • A low-voltage signal is represented by 000

The digits 000 and 111 are called binary digits, or bits. By combining these binary digits in different patterns, computers represent instructions and data.

For example, a computer does not directly understand a written word such as “print.” Instead, that instruction must eventually be represented as a pattern of binary digits. The arrangement of those digits forms the computer’s most direct programming language: machine language.

Machine Language

Machine language is the programming language directly understood by a computer’s processor. It consists of combinations of binary digits, such as 000 and 111.

Because machine language corresponds closely to the electrical operations of the computer, programs written in machine language can be executed directly by the processor. No translator is needed before the computer can use the instructions.

However, machine language is difficult for people to use. A programmer must express every instruction as a binary pattern. Even a simple task can require a long sequence of binary digits.

Advantages of Machine Language

Machine language has several important advantages:

  • It is directly understood by the computer.
  • It does not require a translator.
  • Programs can execute quickly because the processor can use them directly.

Disadvantages of Machine Language

Machine language also creates serious difficulties:

  1. Programs become lengthy.
    Every instruction must be represented using binary digits, so even simple tasks may require a large amount of code.

  2. The code is difficult to understand.
    Binary patterns are difficult for most people to read, remember, and modify.

  3. It is machine-dependent.
    A machine-language program written for one computer may not work on another computer because different machines can have different hardware and instruction systems.

  4. It is time-consuming.
    Writing, checking, and correcting long binary programs requires considerable time.

  5. It is not portable.
    Portability means the ability of a program to run on different computers. Machine-language programs generally cannot be moved easily from one machine to another.

Machine language was used with early computers, including vacuum-tube computers and early transistor-based computers.

Think About It

Machine language is efficient for the processor but difficult for the programmer. This illustrates an important pattern in programming-language development: languages became easier for humans to use by moving farther away from the computer’s raw hardware instructions.

The Five Generations of Programming Languages

As computer technology advanced, programming languages developed through five broad generations. Each generation attempted to improve the weaknesses of earlier languages.

The generations are not simply five unrelated categories. They represent a general movement from machine-oriented programming toward languages that are increasingly closer to human reasoning and problem descriptions.

First Generation: Machine-Level Language

The first generation of programming languages consisted of machine language. It was used approximately from 194019401940 to 195919591959.

These languages contained binary digits, represented by 000 and 111, and were used with early computers.

Main characteristics

  • Directly understood by the computer
  • No translator required
  • Fast execution
  • Extremely difficult for humans to write and understand
  • Machine-dependent
  • Not portable
  • Time-consuming to develop

The first generation focused on what the hardware could directly execute. It provided speed, but programming was complicated and error-prone because every instruction had to be written in binary form.

Second Generation: Assembly Language

The difficulty of machine language led to the development of assembly language, the second generation of programming languages. It was used approximately from 195919591959 to 196519651965.

Assembly language replaced long binary patterns with mnemonics. A mnemonic is a symbolic representation of an instruction. Instead of requiring programmers to remember a binary pattern, the language allowed them to use shorter symbolic codes.

Because of these symbols, assembly language was easier to write and understand than machine language.

Advantages of Assembly Language

Assembly language:

  • Uses symbolic representations instead of only binary digits
  • Is easier for programmers to read
  • Reduces the chance of errors
  • Requires less time to write than machine language
  • Makes instructions easier to remember and organize

The Assembler

A computer cannot directly execute assembly language. Therefore, assembly code must be converted into machine language.

An assembler is a program that translates assembly language into machine language, also called object code. The processor can then execute the resulting machine code.

The basic process is:

  1. A programmer writes source code in assembly language.
  2. The assembler translates the source code.
  3. The assembler produces machine-level object code.
  4. The processor executes the object code.

Limitations of Assembly Language

Assembly language improved programming, but it still had important limitations:

  • It required an assembler before execution.
  • Translation added time to the development and execution process.
  • It remained machine-dependent.
  • A program written for one computer generally could not run on another computer without changes.
  • Programmers still needed different code for different hardware systems.

Both machine language and assembly language are therefore called low-level languages because they are closely connected to the computer’s hardware.

Third Generation: High-Level Languages

The limitations of machine-dependent programming led to the development of the third generation of programming languages, beginning around 196519651965. These languages are still widely used.

Third-generation languages use English-like words and structures instead of binary digits or hardware-specific symbols. This makes them easier for programmers to learn, write, and understand.

Examples of early third-generation languages include:

  • FORTRAN
  • ALGOL
  • COBOL

Examples of modern third-generation languages include:

  • C
  • C++
  • C#
  • Java

Because these languages are easier for humans to use, they are also called high-level languages.

Machine Independence and Portability

A major benefit of third-generation languages is machine independence. A program written for one computer can often run on another computer with no changes or only minor modifications.

This property is called portability.

Machine independence does not mean that the computer can execute the high-level program directly. Instead, the high-level program can be translated for different machines. The same general source code can therefore be adapted to different hardware systems more easily than machine or assembly code.

English-Like Instructions

Third-generation languages use English words to represent:

  • Variables
  • Commands
  • Programming structures
  • Operations

This reduces the difficulty of learning programming. The programmer can focus more on solving the problem and less on remembering the exact binary instructions of a particular processor.

Structured Programming

Third-generation languages support structured programming. Structured programming divides a large program into smaller sections, with each section performing a specific task.

For example, a large student-management program might be divided into sections that:

  • Record student information
  • Calculate grades
  • Produce reports
  • Search for a student
  • Display results

This organization makes a program easier to understand, test, correct, and maintain.

Limitations of Third-Generation Languages

A computer still directly understands only machine language. Therefore, third-generation programs must be translated before execution.

This creates several disadvantages:

  • A translator is required.
  • Translation takes time.
  • Program execution can take longer than direct machine-language execution.

Even with these limitations, third-generation languages became popular because the benefits to programmers were much greater than the disadvantages.

Think About It

Why might a slower-to-execute language still be preferred? The answer is that development time, readability, portability, and ease of maintenance can be more important than maximum direct execution speed.

Fourth Generation: Very High-Level Languages

The fourth generation of programming languages moved even closer to ordinary human language. These languages were designed to be accessible to people who did not have formal training as programmers.

Fourth-generation languages use common English-like syntax and phrases. They can allow a single command to perform several common operations that would require multiple instructions in a lower-level language.

Main Characteristics

Fourth-generation languages:

  • Are highly programmer-friendly
  • Use English-like commands and phrases
  • Can perform multiple operations with one command
  • Work with large collections of information
  • Focus less on individual bits and bytes
  • Are often non-procedural

A non-procedural language focuses on what result is wanted rather than how every step must be performed.

For example, a programmer might specify which records should be retrieved from a database without manually describing every step required to search, compare, and organize those records. The language handles much of the method internally.

Areas of Use

Fourth-generation languages are used in areas such as:

  • Database management
  • Report generation
  • Mathematical optimization
  • Graphical user interface development
  • Web development

Common examples include:

  • SQL
  • NATURAL
  • M-POWER
  • LANSA

Advantages of Fourth-Generation Languages

These languages can:

  • Reduce the amount of code required
  • Make programming easier
  • Process large amounts of information
  • Allow users to describe a desired task directly
  • Increase productivity for common application-development tasks

Limitations of Fourth-Generation Languages

Because the language performs many operations automatically, the programmer has less control over the precise way the task is carried out.

Other limitations include:

  • Less control over program behavior and computer resources
  • Large language packages
  • Greater requirements for disk space
  • Greater requirements for memory capacity

The convenience of a fourth-generation language comes partly from allowing the language system to handle many details on the programmer’s behalf.

Fifth Generation: Problem-Solving and Artificial Intelligence Languages

The fifth generation of programming languages was introduced as a concept in Japan in the early 199019901990s. These languages were designed with an even more ambitious goal: enabling the computer to solve a problem with minimal assistance from the programmer.

In a fourth-generation language, the programmer describes a particular task. In a fifth-generation language, the user describes the problem and the conditions that must be satisfied, while the system attempts to determine how to solve it.

The programmer or user therefore focuses on:

  • What problem needs to be solved
  • What conditions must be met

The user does not need to describe every routine or algorithm used to reach the solution.

Main Area of Use

Fifth-generation languages are used mainly in artificial-intelligence research. Their purpose is connected to automated problem solving and systems that can reason about a problem rather than merely execute a fixed sequence of instructions.

Examples include:

  • OPS5
  • MERCURY

Limitations of Fifth-Generation Languages

Because these systems rely on automated methods, they can be difficult to develop and maintain. Their effective operation may require:

  • More complicated development processes
  • More complicated maintenance
  • Greater computing resources

The fifth generation represents a movement toward systems in which the computer takes greater responsibility for determining how a solution should be produced.

Low-Level and High-Level Languages

The five generations can be grouped into two broad categories.

Low-Level Languages

The first and second generations are called low-level languages:

  • Machine language
  • Assembly language

They are called low-level because they are close to the computer’s hardware and processor instructions.

Low-level languages generally:

  • Depend on a particular machine
  • Are difficult to learn and implement
  • Use binary digits or mnemonics
  • Can interact closely with hardware
  • Are not easily portable

Machine language uses binary digits directly. Assembly language uses symbolic mnemonics that must later be converted into machine language.

High-Level Languages

The third, fourth, and fifth generations are collectively called high-level languages:

  • Third-generation languages
  • Fourth-generation languages
  • Fifth-generation languages

They are called high-level because they are farther removed from the computer’s hardware and closer to human language or human problem-solving methods.

High-level languages generally:

  • Are more machine-independent
  • Are easier to learn and implement
  • Use English-like words and phrases
  • Are more portable
  • Require translation before the computer can execute them
  • Do not interact with hardware as directly as low-level languages

Comparison

FeatureLow-Level LanguagesHigh-Level Languages
GenerationsFirst and secondThird, fourth, and fifth
RepresentationBinary digits or mnemonicsEnglish-like words and phrases
Hardware relationshipClosely connected to hardwareMore independent of hardware
Ease of learningDifficultEasier
PortabilityGenerally lowGenerally high
Hardware interactionDirect or closeLess direct
TranslationMachine language needs none; assembly needs an assemblerRequires a translator

The central trade-off is control versus convenience. Low-level languages provide close interaction with hardware, while high-level languages make programming easier, more portable, and more understandable.

Think About It

A programmer choosing between low-level and high-level languages must consider the task. Close hardware control may favor a low-level language, while portability and development speed may favor a high-level language.

Language Translators

Computers directly understand machine language, but programmers usually prefer assembly or high-level languages because those languages are easier to use. A language translator solves this difference.

A language translator is a program that converts source code written in another programming language into machine code, also called object code. The computer can then execute the translated instructions.

The three main types of language translators are:

  1. Assemblers
  2. Compilers
  3. Interpreters

Assembler

An assembler translates assembly-language source code into machine-language object code.

The process can be expressed as:

Assembly source code⟶Machine-language object code\text{Assembly source code} \longrightarrow \text{Machine-language object code}Assembly source code⟶Machine-language object code

The resulting object code can be executed directly by the processor.

An assembler is necessary because the symbolic mnemonics used in assembly language are easier for humans to understand, but the processor itself understands the corresponding machine instructions.

Compiler

A compiler is a translator that converts a high-level program into machine code.

A compiler scans and translates the entire program as a whole. After translation, the resulting machine code can be executed.

The process can be represented as:

High-level source code⟶Machine code\text{High-level source code} \longrightarrow \text{Machine code}High-level source code⟶Machine code

Compiler Characteristics

  • Translates the complete program
  • Reports errors after scanning the whole program
  • Produces machine code for execution
  • Generally allows faster execution after compilation than statement-by-statement interpretation
  • Requires a separate translation stage before execution

C and C++ are examples of languages commonly associated with compilers.

Interpreter

An interpreter also translates source code into machine-level instructions, but it works differently from a compiler.

An interpreter translates and executes the program statement by statement.

The process is generally:

  1. Read a statement.
  2. Translate the statement.
  3. Execute the statement.
  4. Move to the next statement.
  5. Stop if an error is encountered.

Python and Ruby are examples of languages commonly associated with interpreters.

Interpreter Characteristics

  • Translates one statement at a time
  • Begins execution without translating the entire program first
  • Stops when it encounters the first error
  • Usually takes more overall time to execute a complete program because translation occurs during execution

Compiler and Interpreter Compared

The main difference is how much of the program each translator processes at one time.

FeatureCompilerInterpreter
Translation methodEntire program at onceStatement by statement
Error reportingGenerally after scanning the whole programStops at the first error
Execution processTranslated code is then executedEach translated statement is executed immediately
Overall executionGenerally faster after compilationGenerally slower for complete execution
ExamplesC and C++Python and Ruby

The distinction is important because it affects error handling and execution speed. A compiler can analyze the entire program before execution, while an interpreter can begin running the program sooner but must repeatedly translate statements as the program runs.

Comprehensive Review

A programming language is a formal system for communicating instructions to a computer. It contains vocabulary, keywords, syntax, and semantic rules. Syntax determines whether instructions are written correctly, while semantics determines what those instructions mean.

Computers ultimately understand only machine language, which represents instructions using binary digits, 000 and 111. Machine language is fast and direct but difficult for humans to write, understand, and transfer between machines.

The development of programming languages occurred through five broad generations:

  1. First generation: Machine language using binary digits.
  2. Second generation: Assembly language using symbolic mnemonics.
  3. Third generation: High-level languages using English-like words, portability, and structured programming.
  4. Fourth generation: Very high-level, often non-procedural languages that allow users to describe desired tasks and process large collections of data.
  5. Fifth generation: Languages aimed at automated problem solving, especially in artificial-intelligence research.

The first and second generations are low-level languages because they are machine-dependent and closely connected to hardware. The third, fourth, and fifth generations are high-level languages because they are easier for humans to use and generally more machine-independent.

Because computers cannot directly execute most assembly or high-level source code, translators are needed. An assembler converts assembly language into machine language. A compiler translates an entire high-level program before execution. An interpreter translates and executes the program one statement at a time.

The overall history of programming languages reflects a continuing effort to make computer programming more understandable, portable, efficient, and closer to human problem solving, while still producing instructions that electronic computers can execute.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent