| Feature | Dynamic | Static |
|---|---|---|
| Type Checking | At runtime | At compile time |
| Variable types | Determined when code runs | Declared before running |
| Flexibility | More flexible, less boilerplate | Stricter, but safer |
| Errors | May fail at runtime (type errors) | Type errors caught early (before running) |
| Performance | Usually slower | Usually faster |
| Scope | Better for fast, small personal projects | Better for big projects that needs lots of collaboration |
| Examples | Python, JavaScript | C++, ☕Java |
Dynamic Typing
A language is dynamically typed if the type is associated with run-time values, and not named variables/fields/etc
- You don’t declare variable types explicitly.
- The type is inferred at runtime based on the assigned value.
- Convenience and readability - easier to understand
- The computer decides, so efficiency is low
- Better suited
Static Typing
A language is statically typed if the type of a variable is known at compile time.
- You explicitly declare variable types, or the compiler infers them at compile time.
- Detailedness, lots of safety devices
- Prevents mistakes