Data Type - (Primitive|Native|Built-in)

1 - About

A primitive data type is the basic data type that a language offers.

A primitive data type is then data:

  • that is not an object
  • and has no methods.

Most of the time:

  • a primitive value is represented directly at the lowest level of the language implementation.
  • primitives are immutable (cannot be changed).

They are also scalar.

3 - List

Most primitive data type fall under one of this category:

Others:

4 - Example

  • boolean,
  • byte,
  • short,
  • int,
  • long,
  • char,

5 - Obsession

Primitive obsession is the overuse of primitive types to represent higher-level concepts.

Example with a bounding box represented with:

  • primitives
vector<pair<int, int>> polygon = ...
pair<pair<int, int>, pair<int, int>> bounding_box = GetBoundingBox(polygon);
int area = (bounding_box.second.first  - bounding_box.first.first) *
           (bounding_box.second.second - bounding_box.first.seco
Polygon polygon = ...
int area = polygon.GetBoundingBox().GetArea();

See Code Health: Obsessed With Primitives?

6 - Documentation / Reference

code/type/primitive.txt ยท Last modified: 2018/12/07 13:04 by gerardnico