Language: EN

programacion-tipos-de-datos

What are data types

In programming, data types are a fundamental tool in software development. They define what values can be stored in a variable or data structure.

You know how it is often said:

You cannot add pears and apples

Well, in the same way, it is quite complicated to add a number and a text (in fact, they cannot be added 😅).

That’s why data types are important because they help the compiler or interpreter understand and manage information appropriately and know how to manipulate and handle variables.

It is important to say that your program will have data types (whether you see them or not). In dynamically typed languages, the interpreter hides much of the data management from you. But data types are still there.

If there were no data types, the computer literally would not know how to work with things. It wouldn’t know how to store them, how to manipulate them, or how to add them. Without data types, a computer cannot function

A typical programming language supports several data types. But, in general, we could classify them into:

Primitive data types

Primitive data types are those that are integrated into the programming language and do not require a prior definition.

These data types are found in most programming languages and can vary from one to another, but generally include:

Composite data types

Composite data types are those that contain more than one value. These types can be defined by the programmer or may be integrated into the programming language.

Some examples of composite data types are:

Collections

Collections are composite data types that allow storing multiple elements of the same type in a single structure. Some common examples of collections are Arrays, Lists, or Dictionaries.

[read more]Read more about collections

Groupings

Groupings are composite data types that allow combining different elements into a single entity. Some common examples of groupings are Structs, Objects, and Tuples.

[read more]Read more about groupings

Enumerations

Enumerations are composite data types that represent a finite set of possible values. These values are usually constants and are defined in advance.

Enumerations are useful when you want to restrict a variable or parameter to a specific set of options. For example, an enumeration DayOfTheWeek could have values like Monday, Tuesday, Wednesday, etc.

Unions

Unions (also known as variant data types or variants) allow representing a type compatible with different types. A variable of a union can store one of the several types specified in the union. For example, a union Result could contain a numeric value or an error message, depending on the context.

Reference types

Reference data types are used for indirect data manipulation stored in other variables. These data types do not directly store the value but refer to the location in memory where the value or function is located.

Some examples of reference data types are:

Reference to other variables

A Reference to another variable is a data type that allows accessing and manipulating the value stored in an original variable through a reference. Instead of copying the value of the variable, a Reference is created that points to the memory location where the value is stored.

This means that any change made through the Reference will also affect the original variable. References to variables are especially useful when working with large data structures or when you want to share the same data among different parts of a program.

Reference to functions

A reference to a function is a data type that allows storing the memory address of a function. This allows the development of advanced structures within a program.

Some examples of function references are Callbacks, Events, Filters, and Selectors.

Abstract data types

Abstract data types (ADT) are data types that define a public interface and hide their internal implementation. This means that users of an ADT only need to know how they can interact with it (without needing to know the details of how it is implemented).

Examples of abstract data include Abstract Classes and Interfaces.