<aside> 💡 - Compound data represents information where more than 2 values belong together, such as with coordinates and biodata.
In BSL, compound data is stored in structures.
Structures are built via define-struct
.
Structure definitions include constructors (to build distinct structures), selectors (to extract attribute data from a distinct structure), and predicates (to verify a structure’s data type).
</aside>
When we encounter information where >2 values naturally belong together, such information should be presented in code as compound data — data which possesses multiple attributes/fields.
A compound data type is also known as a structure.
In object-oriented programming languages, compound data can be represented in the form of objects.
<aside> 💡 I like to think of it this way (though I’ve yet to verify how valid this proposition is) — any related data which can be presented within a spreadsheet can also be compressed within a singular compound object/structure.
e.g. Employee biodata; in code, we can create employee objects/structures with multiple attributes like name
, age
, position
, salary
, address
. Such biodata can be presented very simply within a spreadsheet or database.
</aside>
<aside> 🧠 What’s the difference between structures and objects?
As according to the user Donnie in this Stack Overflow discussion,
Generally speaking, objects bring the full object oriented functionality (methods, data, virtual functions, inheritance, etc, etc) whereas structs are just organized memory. Structs may or may not have support for methods / functions, but they generally won't support inheritance and other full OOP features.
Note that I said generally speaking ... individual languages are free to overload terminology however they want to.
</aside>
define-struct