5 ms·
One thing I would add - using negative indices to index from end is a bad idea in general, because you may inadvertently end up with a negative index as a resul
by int_19h 8y ago
One thing I would add - using negative indices to index from end is a bad idea in general, because you may inadvertently end up with a negative index as a result of a calculation that you expected to always be positive - and then instead of an out-of-bounds error, you get silent wrong behavior.
IMO, it's better to have dedicated syntax for index-from-end, as part of the range syntax. Again, Nim does that: x[0..^1] (although unfortunately they didn't make it symmetric).
- thaumasiotes 8y ago> IMO, it's better to have dedicated syntax for index-from-end, as part of the range syntax. This is true, and note that my suggestion requires it -- the only way to distinguish x[-0] from x[0] is to have the parser do it; -0 and 0 are the same number.
- int_19h 8y agoI mean, you could technically distinguish between positive and negative zero, if your numbers are all floating points (like JS or Lua). But that would be even more of a horror show.