3 ms·
Why should the out of bounds behavior be different depending on the semantics of the second parameter?
by gruez 6y ago
Why should the out of bounds behavior be different depending on the semantics of the second parameter?
- masklinn 6y agoBecause if you want to slice to the end you can just ask for the source's length which is free in most languages (it's not in C or in list-based languages), whereas the "result length" version is either going to have to be computed from the collection length or it's a constraint. In the latter case especially it's annoying to have to do weird computations on the basis of length in order to clamp your existing constraint in case the result would already fit.