Codele / Advanced programming
Static and dynamic types
Every value has a type, such as text or a whole number. Some languages check types before the program runs, and others check them while it runs. The same mistake shows up at very different moments.
- A type says what kind of thing a value is, such as text or a whole number. Some actions only make sense for some types.
- Static typing checks types before the program runs (Java, C#, C++, Go). A mistake stops the program from starting.
- Dynamic typing checks types while the program runs (Python, JavaScript). Earlier lines may already have run when the crash comes.
- Static buys safety and better editor help. Dynamic buys speed of writing, with later surprises. Python hints and TypeScript add some static checking on top.
- The code box shows the correct version of line 4. The broken version, name.shout(), is only in the animation because it would not run.
Loading the playable lesson…