Programming Language Principles & Foundations
A programming paradigm is a fundamental style or approach to programming that provides a conceptual framework for solving problems and structuring code. It defines how you think about and organize your program.
Step-by-step instructions
How to do something
Examples: C, Pascal
Objects and classes
Data + methods together
Examples: Java, C++
Mathematical functions
No side effects
Examples: Scheme, Haskell
Facts and rules
What is true
Examples: Prolog, Datalog
How easy is it to understand the code?
How easy is it to write programs?
Does the program behave as expected?
What are the economic implications?
| Feature | Benefit | Performance Cost | Example |
|---|---|---|---|
| Automatic Memory Management | Programmer productivity, safety | GC overhead, unpredictable pauses | Java, Python |
| Dynamic Typing | Flexibility, rapid prototyping | Runtime type checks | Python, JavaScript |
| Virtual Method Calls | Polymorphism, extensibility | Indirect function calls | C++, Java |
| Bounds Checking | Memory safety | Array access overhead | Java, C# |
The vocabulary of the language - individual tokens
How tokens combine to form valid statements
Context-sensitive constraints and scoping rules
The meaning and behavior of valid programs
Execute source code directly without creating machine code
Translate source code to machine code before execution
Compile to intermediate code, then interpret or JIT compile
Macros are text substitution mechanisms that are processed before compilation. The preprocessor literally replaces macro calls with their definitions.
| Aspect | Macros | Functions |
|---|---|---|
| Processing Time | Compile-time (preprocessing) | Runtime |
| Type Checking | No type checking | Strong type checking |
| Performance | No function call overhead | Function call overhead |
| Code Size | Code bloat (inlined everywhere) | One copy in memory |
| Debugging | Harder to debug | Easier to debug |
| Side Effects | Can cause multiple evaluations | Arguments evaluated once |
Invalid characters or tokens
Grammar rule violations
Context-sensitive rule violations
Logical errors in program meaning