mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-22 14:03:10 -05:00
Ex 101: Magic bags better than buckets for metaphors
This commit is contained in:
parent
1c73ad29a7
commit
e5341b91c1
1 changed files with 16 additions and 14 deletions
|
@ -79,19 +79,19 @@ pub fn main() void {
|
||||||
// all about:
|
// all about:
|
||||||
//
|
//
|
||||||
// Let's say you've been tasked with grabbing three glass
|
// Let's say you've been tasked with grabbing three glass
|
||||||
// marbles, three spoons, and three feathers from a bucket. But
|
// marbles, three spoons, and three feathers from a magic bag.
|
||||||
// you can't use your hands to grab them. Instead, you have a
|
// But you can't use your hands to grab them. Instead, you must
|
||||||
// special marble scoop, spoon magnet, and feather tongs to grab
|
// use a marble scoop, spoon magnet, and feather tongs to grab
|
||||||
// each type of object.
|
// each type of object.
|
||||||
//
|
//
|
||||||
// Now, would you rather have:
|
// Now, would you rather the magic bag:
|
||||||
//
|
//
|
||||||
// A. The items layered so you have to pick up one marble, then
|
// A. Grouped the items in clusters so you have to pick up one
|
||||||
// one spoon, then one feather?
|
// marble, then one spoon, then one feather?
|
||||||
//
|
//
|
||||||
// OR
|
// OR
|
||||||
//
|
//
|
||||||
// B. The items separated by type so you can pick up all of the
|
// B. Grouped the items by type so you can pick up all of the
|
||||||
// marbles at once, then all the spoons, then all of the
|
// marbles at once, then all the spoons, then all of the
|
||||||
// feathers?
|
// feathers?
|
||||||
//
|
//
|
||||||
|
@ -103,14 +103,16 @@ pub fn main() void {
|
||||||
// efficient for modern CPUs.
|
// efficient for modern CPUs.
|
||||||
//
|
//
|
||||||
// Decades of OOP practices have steered people towards grouping
|
// Decades of OOP practices have steered people towards grouping
|
||||||
// different data types together into "objects" with the hope
|
// different data types together into mixed-type "objects" with
|
||||||
// that it would be friendlier to the human mind. But
|
// the intent that these are easier on the human mind.
|
||||||
// data-oriented design groups data in a way that is more
|
// Data-oriented design groups data by type in a way that is
|
||||||
// efficient for the computer.
|
// easier on the computer.
|
||||||
//
|
//
|
||||||
// In Zig terminology, the difference in groupings is sometimes
|
// With clever language design, maybe we can have both.
|
||||||
// known as "Array of Structs" (AoS) versus "Struct of Arrays"
|
//
|
||||||
// (SoA).
|
// In the Zig community, you may see the difference in groupings
|
||||||
|
// presented with the terms "Array of Structs" (AoS) versus
|
||||||
|
// "Struct of Arrays" (SoA).
|
||||||
//
|
//
|
||||||
// To envision these two designs in action, imagine an array of
|
// To envision these two designs in action, imagine an array of
|
||||||
// RPG character structs, each containing three different data
|
// RPG character structs, each containing three different data
|
||||||
|
|
Loading…
Reference in a new issue