▲ | mewpmewp2 16 hours ago | |||||||||||||||||||||||||||||||
I'm not native English, but I've done coding for way more than 10+ years, yet I would be able to understand and read quicker Math.min(Math.max(value, min), max) compared to registering in my brain what exactly "clamp" does. In terms of DRY and cleanliness, yes "clamp" sounds awesome. But in terms of practicality and quick understanding? Math.min and Math.max there is such a frequent pattern that brain immediately understands what is being tried to do there, as opposed to exact meaning of "clamp" to me. It may be just me though, clamp is not a word I frequently hear in English, and I see it in code sometimes, but not frequently enough to consciously register what it does as fast in my brain. Despite seeing code for probably 8h+ a day for the past 10 years. If it was in std lib of JS, maybe then it would be better. Like there is some sort of balance line on how frequently something is used and whether it's REALLY worth to abstract it. If it's in stdlib, use it, if it's not use it if truly it's pretty much always used. | ||||||||||||||||||||||||||||||||
▲ | xmprt 16 hours ago | parent [-] | |||||||||||||||||||||||||||||||
Maybe it's different since you're not native English but clamp is as intuitive for me as something like ceil or floor methods. It might not be as simple for someone who is ESL, probably because no major programming languages that I know of include clamp in their standard library like they do with min, max, ceil, floor. I'm also coming from being a Go programmer where the native library is very barebones so a lot of custom utility methods like this are inevitable. | ||||||||||||||||||||||||||||||||
|