ardanlabs / gotour

Apache License 2.0
100 stars 60 forks source link

In Arrays #245

Closed PhilippeZeitoun closed 4 months ago

PhilippeZeitoun commented 8 months ago

Declaring and Initializing Values

it is written "This means that each string has the first word set to nil and the second word set to 0." But, this shouldn't be "This means that each string has the first word set to nil and the second word set to an empty string ("")." ?

alexandear commented 4 months ago

Not really. Let's review the entire paragraph from https://tour.ardanlabs.com/tour/eng/arrays/1:

A string is an immutable, two word, data structure representing a pointer to a backing array of bytes and the total number of bytes in the backing array. Since this array is set to its zero value state, every element is set to its zero value state. This means that each string has the first word set to nil and the second word set to 0.

A string is a two-word data structure. The first word is a pointer to a backing array and the second word represents the total number of bytes. So, "the second word set to 0" is accurate because it refers to the number of bytes.