The datapine Blog
News, Insights and Advice for Getting your Data in Shape

A Beginner’s Introduction To The Most Common Data Types In Programming 

Data types blog post by datapine

In our digitally-driven age, data is permeating every industry and business function at an increasing pace. In fact, it is estimated that approximately 328.77 million terabytes of data are generated every day. Data that, if used correctly, can fuel businesses to high levels of success.

When we talk about correctly using data we mean understanding its properties, types, and conditions in which it should be used. This is especially important for programmers who need to build complex codes and interact with computer systems to do so. 

That is where data types come into play. They enable us to interact with computer systems and tell them how we want our data to be processed and interpreted to translate it into building code and designing systems.

In this post, we will introduce you to the data type definition, provide some insight into why you need them as well as a list of the most common ones. 

What Are Data Types

A data type is an attribute that programmers use to tell a computer how to classify and interpret a piece of data. Understanding and implementing data types in the correct way minimizes the risk of errors ensuring efficient programs are built. 

Essentially, data types tell computers what kind of data is stored in a variable and what mathematical operations are allowed to be performed with that data. Think of variables as boxes that are storing information that needs to be categorized to be useful. For example, a common data type is “int” which is short for Integers, a type composed of whole numbers. By applying the “int” attribute you are telling the system that these are whole numbers and that only addition, subtraction, and multiplication, among others, are the operations that can be performed on it. This same process occurs with other types that define values as characters, decimal numbers, text, and others.  

There are multiple programming languages that use data types in different ways. In some cases, a language requires a variable to be used only with the rules that applied to its type, these languages are known as “strongly typed” and they are usually less prone to error as the computer has the exact instructions to interpret the values, but it is also harder to convert one type to another which translates into less flexibility. Some popular programming languages that are considered to be “strongly typed” include SQL, C, Java, Pascal, and Python, among others. 

On the other hand, other programming languages do not require the specification of the data type and can assume or deduce it, making it easier to convert types without errors. These are known as “weakly or loosely typed” and some common examples include JavaScript, Perl, PHP, Ruby, C, and others. You might notice C can be considered both strongly and loosely typed. This is because it requires data types for variables to be specified but programmers can easily convert types without errors. 

That being said, there is another criterion that differentiates programming languages and their use of data types. This is referred to as static and dynamic typing which are related to strongly or weakly typed, but are not the same as a language that is strongly typed can be dynamic or static as well.

On one side, static typing means that type-checking occurs at compile time, meaning that programmers can spot any kind of issues before the code is running and crashes. On the other side, in dynamic typing, the checking process happens during running time. Where the compiler ignores any type of error and the type-checking process occurs during runtime. If the type checker detects an error, it will notify the developer so he or she can fix it before the system crashes. There is not really a “correct” choice when it comes to static or dynamic typing, in the end, the choice comes down to a stable and clean code but more time-consuming or agile and flexible development which can be more prone to error. 

Now, there are 6 main types that are commonly used across all the mentioned languages. These are bool, int, char, float, string, and array. Each of these is used to provide computers and systems with the necessary instructions and rules to interpret the data depending on its nature. We will look at each of these types in more detail later in the post. But first, let’s talk shortly about why you need them. 

Your Chance: Want to perform advanced analytics with a few clicks?
Try our professional data analysis software for 14 days, completely free!

The Need For Data Types 

As mentioned a few paragraphs before, understanding and using data types help programmers build efficient and reliable codes. This is because in most, not to say all, programming languages, they are fundamental to ensure the data is functioning correctly with no major errors. For example, in Java, a strongly typed language, it is mandatory to indicate the type of all variables, as the system will not compile any type-less operation.  Therefore, knowing each type and when to use it is fundamental.

Now, you might wonder, what use can I have for data types as a business decision-maker? Well, having knowledge of this topic will be useful when collecting and arranging information. For example, if you are performing a customer service survey. The survey can be composed of open questions, drop-down lists, checkboxes, buttons, and others. To store the data you collect from that survey in a database, you need to define the property name and its specific type. This way, the data will be ready to be efficiently analyzed in a customer service dashboard without any errors. 

Likewise, if a database has dates with multiple formats, assigning a “date” type can help “clean” the information and ensure it is consistent and serves its purpose. 

Another example is when building reports using code. While many modern SQL reporting tools automate code-generation saving programmers a lot of time, it is still necessary to have knowledge on the topic to solve any issues that might arise and ensure efficient reports are built. Plus, with this knowledge in hand paired with the help of automation, non-technical users can build SQL reports as well.

List Of Different Data Types In Programming

Data types: primitive, composite, abstract

Now that you have a better understanding of what are data types and why they are important, let’s finally move on to the actual types of data types. It is important to note that the types mentioned here are the most common ones used in various programming languages. Going through all of the existing ones would be a much longer discussion which we will not get into today. That said, let’s dive into our list of data types examples! 

1. Primitive data types

Primitives are predefined data types that contain simple values of specific characteristics, such as numeric or textual and are not based on any other type. They are the most basic form and serve as a building block from which other, more sophisticated types are built. These primitive data types are likely to be used in most programming languages, some with different criteria or names than others, and are usually immediately recognized by programmers. 

  • Integer (int): This is probably the most common primitive type out there. The integer represents whole numbers without a fractional component such as -606, 0, 606. The way this type is defined will vary from language to language. For example, some allow negative numbers while some don’t. 
  • Floating Point: This is also a numeric data type used to represent numbers with fractions, such as 606.06, 0.6, etc. Two types of floating points are recognized: the “float,” which allows up to seven decimal points, and the “double,” which allows up to 15. 
  • Character: As its name suggests, this type represents a string of characters such as letters, punctuation, symbols, and even a blank space.  There are also two variations known as “character string types.” The first one is “CHAR” which represents strings with a default length of 1 to 65000 octets. The second one is “VARCHAR” where the default length is 80 to 65000 octets. 
  • Boolean (bool): It represents the values “true” and “false,” which in some cases are represented as “1” and “0”, respectively. Programmers use this type to show logic in a code, usually in “if/when” statements where a user's specific action determines how the code will continue to run. 
  • None Type (nonetype): Also known as “null,” it represents an empty variable with no meaningful value. It helps programmers realize if they started the code incorrectly or if there are other issues. It is a type on its own, not the same as “false” or “0”. 
  • Short: This is an integer type that represents a whole number. They are known as “short” or “single” integers, and they can be negative or positive.
  • Long: On the contrary, this is known as a “long integer.” It represents integers with 20 negative or positive digits. 
  • Time: Represents values of time with the format hh:mm:ss. It can be used to track the time of day and the time elapsed since a specific event that can be more than 24 hours. 
  • Datetime: Represents values stored as date and time with the formats hh:mm:ss and YYYY-MM-DD. 

2. Composite data types

Composite data types, also known as user-defined or non primitive data types, refer to a composition of different primitive types, usually specified by the user.  There are four big groups of composite types: homogenous which requires all values to be of the same data type; tabular, which stores data in tabular form; semistructured, which stores data as a set of relationships; and multimedia, which stores data in the shape of videos, audio, or images. 

  • Array: Also known as “vector”, an array is a type that represents a group of values of the same type that follow a consecutive order; the position of each value is called the “index”. It is considered a structured data type because it stores multiple values within a single identifier, which can be one-dimensional (arranged as a list) or multi-dimensional (arranged in tabular form).
  • String (str/text): A constant or variable string of characters such as numbers, symbols, and upper or lower case letters, for example, a cellphone number with “+” at the start and “-” to separate numbers. The string can be considered a synonym of the VARCHAR. 
  • Record: As its name suggests, this type represents a collection of fields with their corresponding data types, usually in a table form. For example, an employee record will contain a name, salary, and rank. Records defer from arrays because the fields can be of different types. 
  • Union: A union type contains a group of data objects that can have varied data types (unlike arrays). Unlike records, with unions, each object starts at the same memory location, meaning the union variable can only store one value at a time. When a new value is assigned to a field, the existing one is overwritten. 

3. Abstract data types (ADT)

An abstract data type is a model of a data type that specifies values and operations without specifying how they should be implemented, hence the word “abstract”. In other words, ADTs don’t mention how the data will be organized in memory or what implementation algorithms will be used for the process. It is a theoretical “black box” that hides the inner structure and design from the user. 

The way ADTs are implemented will vary from language to language as each of them have a different logic. For example, in C implementation is done using structures, while on Java is using class. Nevertheless, the data and its operations stay the same no matter the language you are using, making ADTs very popular due to their flexibility and adaptability across languages. 

  • List: A linear collection of values with the same data type that can be implemented using a dynamic array or linked list. Lists can be ordered (alphabetically or numerically), unordered (based on user needs), or indexed (arranged using indexes).  Some of the operations allowed on a list ADT include: get () - return an element from the list at any given point; insert () - insert an element at any position in the list; replace () - replace any element by another, among others. 
  • Stack: One of the most popular ADTs across programming languages, the stack is a collection of values that resemble an actual real-life stack such as a pile of plates. It follows the LIFO structure (last in, first out) where the last value will be the first one to go, meaning operations such as insertion (called “push”) and deletion (called “pop”) can be performed only at one end. Stacks can have a fixed or dynamic sizing and they can be implemented using an array, structure, pointer, or linked list. 
  • Queue: Following a similar logic as stacks, a queue is a linear ADT that can only insert elements of the same data type from one end called rear-end, and delete them from the other, called front-end. Meaning, unlike stacks that use the LIFO principle, queues use the FIFO principle (first in, first out). There are 4 types of queues you can use: the simple queue wich obeys to the FIFO principle; the circular queue where the first element points to the last in the queue utilizing memory better; the priority queue which means each element has a priority, and the double-ended queue which ignores the FIFO principle and can add and remove elements from both ends.

Your Chance: Want to perform advanced analytics with a few clicks?
Try our professional data analysis software for 14 days, completely free!

Final Thoughts On Data Types 

We hope this brief but insightful guide on data types served as the perfect introduction to understanding this complex but interesting topic. We went through a practical programming data type definition, gave a brief explanation of their importance, and finalized with a list of the most common types out there. As mentioned previously, this is just the tip of the iceberg regarding data types. Depending on the programming language, the list, and use cases can go on and on.   

The important takeaway is that being aware of the meaning of data types not only helps programmers build efficient code but can also help businesses manage their data more efficiently, from collection to integration. In the long run, this can translate into better-informed decisions that can skyrocket success. 

With datapine, you can manage and visualize your most critical business data in an engaging and user-friendly way. Try our professional online data analysis software for a 14-day free trial and benefit from smart analytics today!