4 ms·
Deleting from a slice is ugly and awkward because it's slow. Go, like C, confronts you with the real cost of what you want to achieve. A builtin like 'delete(a,
by nemo1618 8y ago
Deleting from a slice is ugly and awkward because it's slow. Go, like C, confronts you with the real cost of what you want to achieve. A builtin like 'delete(a, i)' looks like an O(1) operation, when in reality it's O(n).
- janekm 8y agoA more developer-friendly language like Swift would give you an ArraySlice type with performant views on arrays, and developer-friendly syntax.
- edflsafoiewq 8y agoIn what way does delete(a, i) look like an O(1) operation? It looks like a function call. You can never just look at a function call and see its complexity. You make it sound like deleting an element being ugly is a design choice, but it can't be a choice since there is no alternative. Swap-and-pop is O(1), but it's ugly too.
- kasey_junk 8y agoYet copy is available.
- apta 8y ago> A builtin like 'delete(a, i)' Ironically, "delete" is built in in golang (how else do you delete an entry from a map)? Yet it says nothing about its cost.