Skip to content
Devgo

Data type

A classification of data that determines what values are possible and what operations are valid. Common types: number, string, boolean, array, object. Static typing (Rust, Java) checks types at compile time; dynamic typing (Python, JS) checks at runtime.

When to use
  • Always — every language has types.
When not to
  • Never.

Definition

A defines a set of values and operations. Primitives (int, float, bool, char) are single values. Composite types (arrays, structs, objects) combine values. Type systems can be static (checked at compile time) or dynamic (checked at runtime), strong or weak.

Why it exists

To prevent errors (you can't add a number to a string meaningfully), enable compiler optimization, and document intent.

How it works

In static languages, the compiler infers or requires type annotations and rejects type errors before running. In dynamic languages, types are checked at runtime (TypeError). Some languages (, type hints) add optional static checking.

Scaling limits

Complex type systems ( generics, lifetimes) have a learning curve. Dynamic typing catches errors late (at runtime).

Cost shape

Free.

Alternatives

  • No types (assembly) — Maximum flexibility, maximum bugs.

Failure modes

  • Type errors at runtime in dynamic languages.
  • Overly complex generic types.
  • Implicit type coercion bugs (JS).

,