| ▲ | samdoesnothing 5 hours ago | |||||||||||||||||||||||||
Pushing everything to types like this creates a different burden where you're casting between types all over the place just to use the same underlying data. You could just clamp velocity to 200 in the callee and save all that hassle. | ||||||||||||||||||||||||||
| ▲ | kennywinker 4 hours ago | parent [-] | |||||||||||||||||||||||||
Casting? Not really - i think you’d only need a couple type checks. Imo this is mostly useful for situations where you want to handle input validation (and errors) in the UI code and this function lives far away from ui code. Your point about clamping makes sense, and it’s probably worth doing that anyway, but without it being encoded in the type you have to communicate how the function is intended to be used some other way. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||