> If you pass an out-of-range argument, you should reject it using a
precondition

Different use case. I have a circular buffer.

> . And if for some reason you really *do* want to force the value into the
range, clamping it to the bounds of the range seems like a more sensible
solution than modulo

I have a circular buffer, I don't want to be clamping it to the bounds of
the range.

> I'm sure there are cases where you *would* want to do this, but they seem
like they'd be few and far between.

It's the 'correct' implementation of modulo.

On Sat, May 21, 2016 at 4:40 PM, Brent Royal-Gordon <[email protected]>
wrote:

> > You are not taking into account when a function is passed an argument
> and needs it to be in some range.
>
> If you pass an out-of-range argument, you should reject it using a
> precondition, thrown error, or nil return value. And if for some reason you
> really *do* want to force the value into the range, clamping it to the
> bounds of the range seems like a more sensible solution than modulo. I'm
> sure there are cases where you *would* want to do this, but they seem like
> they'd be few and far between.
>
> --
> Brent Royal-Gordon
> Architechies
>
>
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to