PROGRAMMING BASICS
Machine Languages
- they are machine dependent
- language that is directly understood by a
computer's CPU
- consists of binary code (sequence of 0s
and 1s)
Instructions and Data
Mnemonics
- help us to remember things by
remembering short rhymes
Assembly Languages
- a human-readable representation of
machine code (binary)
Assembler
- a tool or software program used to
convert human-readable assembly
language code into machine language
- uses mnemonics and symbols to
represent CPU instructions and memory
addresses
- what programmers use
PROGRAMMING LANGUAGES
English-like language
Compiler VS Interpreter
Compiler
- translates the entire source code program
into machine code or an intermediate
form before execution
- machine code can be executed multiple
times without the need for recompilation
(faster execution times)
- early error detection
- C, C++, Java, Rust
Interpreter
- translates and executes the source code
line by line or statement by statement
- reads, translates, and executes the code
sequentially
- can detect errors in the code as they
occur but may stop execution at the first
encountered error
- Python, Ruby, JavaScript
High-level Languages
- easier for programmers to write code that
is more readable, understandable, and
maintainable
- abstract away many of the complexities of
computer hardware, such as memory
management and CPU operations
- use human-readable syntax with
meaningful keywords and symbols
- portable, meaning it can run on different
computer platforms with minimal or no
modification
- built-in functions, libraries, and tools
- features that help prevent common
programming errors, such as type
checking, bounds checking, and
automatic memory management (e.g.,
garbage collection)
DEBUGGING
Types of Errors
1. Syntax Error
- when the code violates the rules of the
programming language's syntax
- typographical mistakes, missing or
misplaced punctuation, incorrect keyword
usage, etc.
- ex: forgetting to close a parenthesis,
misspelling a variable name, or using an
incorrect operator
2. Run-time Error
- typically caused by unexpected
conditions or inputs that the program
cannot handle
- division by zero, attempting to access an
out-of-bounds array index, using a
variable before it's initialized, etc.
- detected when the program is executed
(program termination or the generation of
error messages)
- ex: trying to open a file that doesn't exist
or attempting to divide by zero
3. Logic Error
- when the code's logic or algorithm is
incorrect, leading to unintended or
incorrect behavior
- result of mistakes in the program's design
or algorithm
- can be challenging because the code
runs without error messages
- code inspection, testing, and logic
analysis are used to identify and correct
logic errors
- ex: an incorrect formula for calculating the
area of a circle, leading to incorrect
results
OOP CONCEPTS
Class
- blueprint or template for creating objects
- defines a set of state/attributes and
methods (functions) that characterize the
objects created from the class
- encapsulate the common properties and
behaviors that objects of a certain type
share
- ex: "Car" class that defines the attributes
(color, make, model) and methods (start,
stop, accelerate)