Learning Objectives

By the end of this chapter, you will be able to:

  • Define a programming language.
  • Differentiate between low-level and high-level programming languages.
  • Understand the role of a compiler and an interpreter.

What is a Programming Language?

A programming language is a formal language comprising a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms.

Most programming languages consist of instructions for computers. There are programmable machines that use a set of specific instructions, rather than general programming languages.

Low-Level vs. High-Level Languages

Programming languages can be broadly categorized into two types: low-level and high-level.

Low-Level Languages

Low-level languages are closer to the computer’s native machine code and provide little to no abstraction from the hardware.

  • Machine Language: The lowest-level language, consisting of binary code (0s and 1s) that the CPU can directly execute. It is not human-readable.
  • Assembly Language: A step above machine language, assembly uses mnemonics (short, human-readable words) to represent machine-level instructions. It must be converted to machine code by an assembler.

High-Level Languages

High-level languages are closer to human language and provide a high degree of abstraction from the hardware. They are designed to be easy for humans to read, write, and maintain.

  • Characteristics: Use English-like syntax, are easier to learn, and are more portable across different computer architectures.
  • Examples: Python, Java, C++, C#, JavaScript, and Ruby.

Compilers and Interpreters

Since computers can only understand machine code, high-level languages must be translated. This is done by either a compiler or an interpreter.

  • Compiler: A compiler translates the entire source code of a program into machine code before the program is run. The resulting machine code is then saved as an executable file that can be run at any time.
    • Process: Source Code -> Compiler -> Machine Code (Executable File)
    • Examples: C and C++ are typically compiled languages.
  • Interpreter: An interpreter translates and executes the source code line by line, at the same time. No separate executable file is created.
    • Process: Source Code -> Interpreter -> Execution (line by line)
    • Examples: Python and JavaScript are typically interpreted languages.

Summary

Programming languages are the tools we use to give instructions to computers. They range from low-level languages like machine and assembly language, which are close to the hardware, to high-level languages like Python and Java, which are closer to human language. High-level languages must be translated into machine code by either a compiler (which translates the whole program at once) or an interpreter (which translates it line by line) before the computer can execute them.

Key Takeaways

  • Programming languages are used to write instructions for computers.
  • Low-level languages (machine, assembly) are close to the hardware, while high-level languages (Python, Java) are closer to human language.
  • Compilers translate the entire program at once, while interpreters translate it line by line.

Discussion Questions

  1. What are the main advantages of using a high-level language over a low-level language?
  2. What is the difference between a compiler and an interpreter?
  3. If you were creating a new software application, what factors would you consider when choosing a programming language?