Strongly Typed Languages
- A type describes what an item of data represents conceptually
- A type system is a set of rules constraining how types can be used
- Type systems eliminate certain classes of bugs without adding too much complexity
- Strongly typed languages enforce type rules with no escape hatches
- Weakly typed languages allow circumvention of type rules (e.g., casts in C)
Static vs. Dynamic Typing
- Static typing: variable types are fixed and cannot change
- Dynamic typing: types can change during program execution
- Systems languages tend to favor static types for performance
Safe vs. Unsafe Languages
- Safe languages ensure operations conform to typing rules
- Unsafe languages allow operations outside the typing rules
- Strong typing makes results well-defined and prevents undefined behavior
- C has 193 different kinds of undefined behavior
- Modern systems programming language initially developed by Graydon Hoare, sponsored by Mozilla
- 1.0 released in 2015, backwards-compatible updates every 6 weeks
- Combines control with safety guarantees
Basic Rust Types and Operations
- Similar primitive types to C but with more consistent naming
bool type (unlike C which uses integers)
char is a 32-bit Unicode scalar value (not a byte like in C)
- Arrays have bounds checking at runtime
- Vectors for variable-length lists
- Tuples for collections of unnamed values of different types
- Structs for named collections of values
Traits, Enums, and Pattern Matching
- Traits define shared functionality (similar to interfaces)
- Enums represent alternatives (more powerful than C enums)
Option<T> type for values that might not exist
Result<T, E> for operations that might fail
- Pattern matching with exhaustive
match statements forces handling all cases
- References similar to pointers in C but with safety guarantees
- Immutable vs. mutable references
- Borrowing rules:
- Cannot have null references
- Many immutable OR one mutable reference at a time
- Original object inaccessible during mutable reference
- Box type for heap allocation
- String handling with
&str (immutable slices) and String (mutable)
Why Rust is Interesting
- Safe, modern type system with no undefined behavior
- Memory safety prevents buffer overflows, dangling pointers, null dereferences
- Ownership tracking prevents iterator invalidation, use-after-free bugs
- Concurrency rules prevent data races
- Retains the control needed for Systems Programming