Re:Strict APIs vs. Forgiving APIs
by gruez on Wednesday October 28, 2020 @12:26PM
(#24920685)
Why should the out of bounds behavior be different depending on the semantics of the second parameter?
[ Parent
| on HN ]
Because 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.