Day 20 - Common data types and data structures
As product managers, it's important to have a basic understanding of data types, as they play a crucial role in how we design and develop our products.
I hope you enjoyed yesterday's post on the modeling language you can use to design a database. I'm looking forward to your submissions for the "Design a Database in ERD" challenge. The submission form is here.
In today's post, we are going to go one step deeper in database design and learn more about data. And more correctly about Data Types and Data structures.
Buckle up, it'll be a geeky road ahead! You can also go over the slides over here.
Data types
As product managers, it's important to have a basic understanding of data types, as they play a crucial role in how we design and develop our products.
Data types define the kind of data that a program can handle and the operations that can be performed on that data. In this post, we'll take a look at some common data types and why they are important for product managers to know about.
Common data types
Integer
An integer is a whole number that can be positive, negative, or zero. Examples include 42
, -23
, and 0
.
Floating point
A floating point number is a number with a decimal point and can represent fractional values. Examples include 3.14
, -0.01
, and 1.0
.
String
A string is a sequence of characters and is often used to represent text. Examples include "Hello, world!"
, "This is a string"
, and "123"
.
Boolean
A boolean is a data type that can have one of two values: True
or False
. Examples include True
, False
, and False
.
Array
An array is a data type that stores a collection of values and can be of any data type. Examples include [1, 2, 3]
, ["a", "b", "c"]
, and [True, False, True]
.
Dictionary
A dictionary (also called a map or associative array) is a data type that stores a collection of key-value pairs, where each key is associated with a value. Examples include {"a": 1, "b": 2, "c": 3}
, {"name": "John", "age": 30}
, and {"True": "Yes", "False": "No"}
.
Set
A set is a data type that stores a collection of unique values and does not allow duplicate values. Sets are often used for tasks like searching and filtering and can be implemented using various data structures such as hashtables or trees.
Tuple
A tuple is a data type that stores a fixed-length sequence of values and can be of any data type. Tuples are often used to store related pieces of data that should not be modified and can be accessed using indexing or unpacking.
Mainly used in Python, tuples are similar to lists except for the following:
A quick guide on the nomenclature here:
Immutable means the tuple object can't be modified after it's created. If you want to change something, you need to create a new one with a copy of the data + the modified element.
Because they are immutable, their size will be fixed too. (as no element can be added or removed).
Function
A function is a data type that represents a block of code that can be executed and can accept parameters, and return a result. Functions are often used to encapsulate reusable code and can be passed as arguments or returned as values from other functions.
Examples of languages that
function
is a data types are Javascript and C/C++.
Object
An object is a data type that represents a complex data structure and can contain a combination of different data types and methods. Examples might include an object representing a person, with properties such as name, age, and address.
🤓 When designing a database, most of the time we are designing the tables to copy the Objects used in the code and save them in databases. This concept is called "persisting" the data. Most of the time there will be additional columns in the table that are not part of the object, such as data it's created, edited, deleted, etc.
Class
A class is a data type that represents a blueprint for creating objects and can contain data (properties) and behavior (methods). Classes are often used to model real-world concepts and can be used to create objects that share a common structure and behavior.
In another word, Objects are created from Classes.
Enum
An enum (short for enumeration) is a data type that represents a set of predefined constants and is often used to represent a set of related values that do not change. Enums can be used to make code more readable and prevent the use of magic values.
Wrap up
It's important to note that the specific data types and their characteristics will vary depending on the programming language being used. Some languages, such as dynamically typed languages like Python, have a more flexible type system and allow for the creation of custom data types, while other languages, such as statically typed languages like Java, have a more rigid type system and define a fixed set of data types.
Understanding data types is an essential skill for product managers, as it can help us make informed decisions about how to design and develop our products, communicate more effectively with technical team members, and understand the trade-offs and limitations of different approaches. I hope this post has provided a helpful overview of some common data types, and encourages you to continue learning and exploring this important topic.