In my perspective, when it comes to creating a web product, everything revolves around data. Views request and display data to the user, the server interlinks different sources of data, modifies it, and sends it elsewhere, while a database stores and retrieves data. This perspective has served me well in my work, allowing me to understand my clients’ systems quickly by focusing on the flow of data. It also eliminates unnecessary implementation details, helping me concentrate on what’s important.

A strong understanding of data structures is essential. How can we understand what’s happening if we can’t recognize the data and how it’s being modified?

Here, I’ll list the data types and structures I encounter the most, along with their implementations in Rust.

Generated by DALL-E 3

Structuring Data

There are myriad ways to structure data, allowing us to manage it in ways that best serve its use case.

Primitives

Understanding primitives is important as these are the building blocks of complex JSON objects found everywhere.

There are some types that are not primitives but are often used similarly.

Compound Data

Data grouped together with some rules.

Collections

More complex groupings and implementations of data structures.

Vector

Useful for single-dimensional data with varying length. It can also be used as Stack and Queue data structures.

Set

Useful when we want to ensure all values are unique.

Map

Useful for storing data to process multiple times without needing to iterate through the entire list to find items.

Buffer

All data is a series of 1s and 0s. When we want to work with a string, we tell the program to interpret that data as a string. That’s why in most languages, when doing I/O, we’ll have an initial step of putting the received data into a Buffer before converting it to a usable format.

I had done a small DNS client to understand how DNS works using NodeJS. That also required the use of Buffers.

Complex Types

We can define our own complex types at any point and define the behavior of the data. The sky’s the limit; we can make this as complex or as simple as required.

Data Mutation

There is a lot of nuance when it comes to modifying data. We could be mutating the data directly, working on the data in a way that creates new modified data while keeping the original data immutable, or doing a mix of both. Everything depends on the specific use case.

Mutable Data

Let’s add a system that registers a birthday event for a person to the previous implementation of the Person struct.

This sad birthday implementation will mutate the existing data for the Person data in the variable shivam.

Immutable Data

Immutable means that the data being operated on is not modified while performing an operation. In this example, I have removed the sad birthday method and introduced a happy child birth event.

Here, the parent data is not modified in any way, and a new child is created with references to the parent Person data.

Note: We have also created a Binary Tree data structure here since it fits to describe this use case.

Mixed

We don’t need to fix our systems to one single style. We can use mutability and immutability where it fits.

This implementation looks pretty confusing due to the nature of the Rust borrow checker. We need to manage references and lifetimes.

In this implementation, we mix mutable and immutable data. While creating new data, we can reference existing data without modifying it, ensuring safe and predictable data manipulation.

Conclusion

Understanding data structures is key to effective web development. Each type, from primitives to custom types, impacts application efficiency and performance. Focusing on data flow and manipulation helps design robust, scalable solutions.

A solid grasp of data structures ensures efficient, maintainable code and optimized performance. Incorporating these concepts enhances technical skills and aids in navigating complex systems. Keep exploring and experimenting to find the best fit for each challenge.

Data Structures in Web Development was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.

​ Level Up Coding – Medium

about Infinite Loop Digital

We support businesses by identifying requirements and helping clients integrate AI seamlessly into their operations.

Gartner
Gartner Digital Workplace Summit Generative Al

GenAI sessions:

  • 4 Use Cases for Generative AI and ChatGPT in the Digital Workplace
  • How the Power of Generative AI Will Transform Knowledge Management
  • The Perils and Promises of Microsoft 365 Copilot
  • How to Be the Generative AI Champion Your CIO and Organization Need
  • How to Shift Organizational Culture Today to Embrace Generative AI Tomorrow
  • Mitigate the Risks of Generative AI by Enhancing Your Information Governance
  • Cultivate Essential Skills for Collaborating With Artificial Intelligence
  • Ask the Expert: Microsoft 365 Copilot
  • Generative AI Across Digital Workplace Markets
10 – 11 June 2024

London, U.K.