C++ 0002 — Introduction to Programming Languages

Modern computers are incredibly fast, with advancements continuing at a rapid pace. Despite their speed, computers have notable constraints: they natively understand only a limited set of instructions and require explicit directions to perform tasks.

A computer program, often referred to as an application, is a sequence of instructions that a computer follows to achieve specific outcomes. Programs are crafted using programming languages, which simplify the process of creating instructions for computers.

The act of writing programs using a programming language is known as programming. Programmers write source code, which is essentially text files containing instructions written in a programming language. When these instructions are processed by the computer, it is said to be running or executing the program. Programs execute on the computer’s hardware, the physical components of a computer.

Key Hardware Components in a Typical Computer

  1. Interactive devices (e.g., monitors, touchscreens, keyboards, mice): Facilitate user-computer interaction.
  2. Storage devices (e.g., hard drives, SSDs): Retain information even when the computer is powered off.
  3. Memory (RAM): Temporarily stores programs before execution.
  4. CPU (Central Processing Unit): Executes instructions and is often referred to as the computer’s “brain.”

Modern programs interact with both hardware and software, including operating systems (OS). A platform refers to a combination of compatible hardware (like a CPU) and software (such as an OS or browser) that supports software applications. For instance, a “PC” commonly refers to a Windows OS running on an x86-family CPU.


Machine Language

A computer’s CPU cannot directly understand C++. Instead, it processes instructions in machine language, which is a series of binary codes (e.g., 10110000 01100001). These instructions perform specific operations, such as comparing numbers or transferring data. Early programmers had to write in machine language, a challenging and time-intensive process.

Key Points About Machine Language

  1. Machine language instructions are sequences of binary digits (bits).
  2. Each CPU family (e.g., x86, ARM) has a unique instruction set, meaning machine language programs are not compatible across CPU families.

Assembly Language

To make programming more manageable, assembly language was developed. Assembly replaces binary instructions with readable abbreviations (e.g., mov al, 061h). While easier to understand than machine language, assembly programs still require translation into machine language via an assembler.

Downsides of Assembly Language

  1. Complexity: Assembly programs are difficult to understand and require many instructions for simple tasks.
  2. Lack of Portability: Each CPU family has its own assembly language, limiting cross-platform compatibility.

High-Level Languages

To overcome the challenges of machine and assembly languages, high-level languages like C, C++, and Java were created. These languages:

  1. Are easier to read and write.
  2. Require fewer instructions for complex tasks.
  3. Promote portability across platforms.

Translation Methods

  1. Compiling: Converts high-level code into machine language, producing an executable file that can run without the compiler.
  2. Interpreting: Directly executes high-level code, but requires the interpreter to be present on the target machine.

Advantages of High-Level Languages

  • Readability: Closer to natural language, making them easier to learn.
  • Conciseness: Single-line instructions in C++ can replace multiple assembly instructions.
  • Portability: Programs can be compiled to run on multiple platforms with proper care.

Portability Considerations

Factors like platform-specific features, third-party library limitations, and compiler-specific extensions can impact portability. While targeting a single platform may simplify development, adopting cross-platform strategies can broaden an application’s reach.


Rules, Best Practices, and Warnings

Throughout these tutorials, key points will be highlighted under these categories:

  1. Rule: Mandatory actions required by the language for proper functionality.
  2. Best Practice: Recommended approaches for conventional or superior results.
  3. Warning: Actions to avoid due to potential errors or unexpected outcomes.

By following these principles, you can create robust and efficient C++ programs that adhere to modern development standards.

0002 — Introduction to Programming Languages

Modern computers are incredibly fast, with advancements continuing at a rapid pace. Despite their speed, computers have notable constraints: they natively understand only a limited set of instructions and require explicit directions to perform tasks.

A computer program, often referred to as an application, is a sequence of instructions that a computer follows to achieve specific outcomes. Programs are crafted using programming languages, which simplify the process of creating instructions for computers.

The act of writing programs using a programming language is known as programming. Programmers write source code, which is essentially text files containing instructions written in a programming language. When these instructions are processed by the computer, it is said to be running or executing the program. Programs execute on the computer’s hardware, the physical components of a computer.

Key Hardware Components in a Typical Computer

  1. Interactive devices (e.g., monitors, touchscreens, keyboards, mice): Facilitate user-computer interaction.
  2. Storage devices (e.g., hard drives, SSDs): Retain information even when the computer is powered off.
  3. Memory (RAM): Temporarily stores programs before execution.
  4. CPU (Central Processing Unit): Executes instructions and is often referred to as the computer’s “brain.”

Modern programs interact with both hardware and software, including operating systems (OS). A platform refers to a combination of compatible hardware (like a CPU) and software (such as an OS or browser) that supports software applications. For instance, a “PC” commonly refers to a Windows OS running on an x86-family CPU.


Machine Language

A computer’s CPU cannot directly understand C++. Instead, it processes instructions in machine language, which is a series of binary codes (e.g., 10110000 01100001). These instructions perform specific operations, such as comparing numbers or transferring data. Early programmers had to write in machine language, a challenging and time-intensive process.

Key Points About Machine Language

  1. Machine language instructions are sequences of binary digits (bits).
  2. Each CPU family (e.g., x86, ARM) has a unique instruction set, meaning machine language programs are not compatible across CPU families.

Assembly Language

To make programming more manageable, assembly language was developed. Assembly replaces binary instructions with readable abbreviations (e.g., mov al, 061h). While easier to understand than machine language, assembly programs still require translation into machine language via an assembler.

Downsides of Assembly Language

  1. Complexity: Assembly programs are difficult to understand and require many instructions for simple tasks.
  2. Lack of Portability: Each CPU family has its own assembly language, limiting cross-platform compatibility.

High-Level Languages

To overcome the challenges of machine and assembly languages, high-level languages like C, C++, and Java were created. These languages:

  1. Are easier to read and write.
  2. Require fewer instructions for complex tasks.
  3. Promote portability across platforms.

Translation Methods

  1. Compiling: Converts high-level code into machine language, producing an executable file that can run without the compiler.
  2. Interpreting: Directly executes high-level code, but requires the interpreter to be present on the target machine.

Advantages of High-Level Languages

  • Readability: Closer to natural language, making them easier to learn.
  • Conciseness: Single-line instructions in C++ can replace multiple assembly instructions.
  • Portability: Programs can be compiled to run on multiple platforms with proper care.

Portability Considerations

Factors like platform-specific features, third-party library limitations, and compiler-specific extensions can impact portability. While targeting a single platform may simplify development, adopting cross-platform strategies can broaden an application’s reach.


Rules, Best Practices, and Warnings

Throughout these tutorials, key points will be highlighted under these categories:

  1. Rule: Mandatory actions required by the language for proper functionality.
  2. Best Practice: Recommended approaches for conventional or superior results.
  3. Warning: Actions to avoid due to potential errors or unexpected outcomes.

By following these principles, you can create robust and efficient C++ programs that adhere to modern development standards.