7 ms·
The bloat of edge-case first libraries
- 01HNNWZ0MV43FF 1y ago3 of those 4 examples wouldn't exist in a statically-typed language like TypeScript
- ants_everywhere 1y agoYes this is just ad hoc runtime type checking
- mewpmewp2 1y agoAlternative -> could just use something like Zod or have native stdlib Zod like type of thing to improve a lot on this type of edge case handling. Although if performance is key, then might question how much this constant parsing and validation would add on top, but in 99% cases probably wouldn't matter.
- BobbyTables2 1y agoHow are the download rates of these things so high? Are there 1000 people running 100 CI pipelines/day where downloads aren’t cached?
- GenerocUsername 1y agoYes
- kingstnap 1y agoYep. True webscale is astronomical levels of inefficient and wasteful usage of bandwidth and CPU.
- nerdponx 1y agoIt doesn't help that container images typically require you to "opt in" to sharing a cache with the host system. Docker even has a special file mount type for it. I find that people on average don't have a lot of interest in making such things work, they see that it's not available right in front of them and shrug and say "oh well" because ultimately it doesn't hurt them much.
- phito 1y agoYeah I'd say most people view it as such, until they hit (docker hub) rate limits.
- BobbyTables2 1y agoLocal caching is also a royal pain when one has multiple CI runners, besides the hassle of Docker related configuration. Do they cache to shared storage and worry about concurrency? Do they only have local storage in various differing states?
- zahlman 1y agoIt seems to happen in the Python world, too. Check out the stats for the most commonly downloaded packages from PyPI (https://pypistats.org/top https://pypistats.org/top), and also consider which packages are on the list. (Pip used to be right up there next to setuptools. It's still pretty popular — https://pypistats.org/packages/pip https://pypistats.org/packages/pip — but uv has clearly changed the equation.)
- swiftcoder 1y agoYep, every single transitive downstream consumer pulls a fresh copy on every CI run. It's kind of ridiculous, and it's like this in every modern ecosystem. For example, this is a completely empty rust crate, which I started years ago and never released, and it's still downloaded multiple times per day... https://crates.io/crates/ruble https://crates.io/crates/ruble
- fainpul 1y agoI'm confused. Why did you publish this? Who "uses" it?
- swiftcoder 1y agoI published it purely to placeholder the name (and then life got in the way, and I never released the actual library). Nobody uses it at all, but some CI system is still polling at regular intervals...
- qludes 1y agoSo someone could reserve all the pronounceable crate names?
- swiftcoder 1y agoYeah, it’s a known problem in the (non-namespaced) crates.io ecosystem. If someone else wants this name for their Bluetooth LE crate, I’ll happily hand over the keys, but obviously not every crate-squatter is so principled
- fainpul 1y agoBut if no other crate depends on your crate and nobody directly uses it, why would any CI system download it?
- swiftcoder 1y agoI think some of the CI systems just monitor all published crates. For example, docs.io potentially pulls it to see if there is any new documentation
- mrweasel 1y agoHave you noticed how much stuff breaks when Github or NPM is down? People do not cache, they do not mirror, modern development for large parts are just people YOLO-ing it.
- b_e_n_t_o_n 1y agoJavaScript had to implement these checks because you could pass a function literally anything and it was on the implementation to deal with it. Typescript has this same problem tbh.
- Spivak 1y agoI mean they clearly don't have to, Python has the same problem of being able to pass anything—you don't see this kind of incredibly defensive programming. But Python set a culture of being for "consenting adults" where it's expected that callers will read the docs and ensure preconditions are satisfied, and if they don't whatever happens, happens. It leads to less code, and more generalizable code. Maybe the caller does know what they're doing, who am I to say they can't.
- pcwelder 1y ago>if they don't whatever happens, happens What happens is you get an error. So you immediately know something is wrong. Javascript goes the extra mile to avoid throwing errors. So you've 3>"2" succeeding in Javascript but it's an exception in python. This behavior leads to hard to catch bugs in the former. Standard operators and methods have runtime type checks in python and that's what examples in the article are replicating.
- recursivecaveat 1y agoIt's so strange to me that JS goes so far to avoid errors, mashing random stuff into strings or NaNs, misspelled variables just become undefined, etc. Then when your off-the rails program reaches `undefined()` it's "woah woah woah, that's clearly nonsense, stop program execution right this instant". I feel like I could respect it a little more if they committed to "a webpage should never crash under any circumstances" and there were just no exceptions in the language whatsoever.
- watwut 1y agoIt has nothing to do with the wish to not crash page. Javascript was a prototype that was supposed to be refined and cleaned. Then management said "we will ship it now" and it was shipped as it was. At the time, they thought it will be used for small things, minor snippets on web page. Webapps as we have them were not a thing yet.
- 0x20cowboy 1y agoI agree with the spirit of this, but I’d go one more step with the example: export function clamp(value: number, min: number, max: number): number { return } That is just adding an extra jump and entry on the callstack where you could just have done: Math.min(Math.max(value, min), max); Where you need it. (The example used was probably just for illustration though)
- chii 1y ago> you could just have done ... i disagree with this particular example - it's actually a good use case for being a utility maths function in a library. I mean, the very `min()` and `max()` function you used in the illustration could also have been used as an example, if you use the same logic!
- mewpmewp2 1y agoI'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 1y agoMaybe 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.
- phito 1y agoI've only seen these kind of libraries in JavaScript. They are a direct result of poor language design.
- procaryote 1y agoNothing in javascript makes you have tiny pointless libraries that check if something is odd or if something is an array(ish). This is just a quirk of javascript developer culture At some point someone went "let's decouple as much as we can! A library should be just a single function!" and we've spent a lot of time since then showing why that's quite a bad idea The lack of types perhaps inspires some of these functions masquerading as libraries, but they're often trivial checks that you could (and probably should) do inline in your less pointless functions, if needed.
- pornel 1y agoProperties of a language shape the tooling and culture that develops around it. JS has exploded in popularity when Internet Explorer was still around, before ES6 cleanup of the language. JS had lots of gotchas where seemingly obvious code wasn't working correctly, and devs weren't keeping up with all the dumb hacks needed for even basic things. Working around IE6's problems used to be a whole profession (quirksmode.org). Browsers didn't have support for JS modules yet, and HTTP/1.1 couldn't handle many small files, so devs needed a way to "bundle" their JS anyway. Node.js happened to have a solution, while also enabled reusing code between client and server, and the micro libraries saved developers from having to deal with JS engine differences and memorize all the quirks.
- procaryote 1y agoIn other languages people build abstraction libraries for that, like apache portable runtime that gives you a consistent api for most things you need to build a web-server, using just one dependency. That would also save you needing to memorise all the micro libraries needed to work around the relevant quirks. Splitting it into a library per quirk seems like an unforced error in that context. One could have excused it as being a way to keep the code size down, but if you use npm you also usually use a build step which could drop the unused parts, so it doesn't really hold water
- khaledh 1y agoThis is why every language needs a good standard library, which unfortunately JavaScript never had.
- franciscop 1y agoI've tried to optimize to avoid these before. The problem is that these libraries are normally not used directly, they are usually pretty low in the dependency tree (root?). The farther you go down in the dependency tree, the older the packages are, where rightfully there's some reluctance to update things for the sake of updating things, risking breaking a stable library. It's a tricky thing and not so easy as to just say "don't use npm's `is-array`, use `Array.isArray()` instead", since every JS/TS package author writing code in 2025 knows that already. It'd be a lot more productive to ask the authors of the (normally bigger, user-facing) libraries that you use nowadays to avoid using these libraries with deep and outdated dependencies. e.g. I stopped using Storybook because of this, but I'm happy to see that they've been working on cleaning up their dependency tree and nowadays it's much better: https://storybook.js.org/blog/storybook-bloat-fixed/ https://storybook.js.org/blog/storybook-bloat-fixed/
- tobr 1y agoI would be a little upset if a clamp function could throw a validation error when I passed only numbers. I’ve always written clamp to work even if min is larger than max. Basically, clamp comes down to sorting the three numbers and returning the middle one. I’ve never thought of that as an edge case, it just seems like a more general way to think of the operation that gives you less surprises since every possible input has a well-defined output.
- nerdponx 1y agoThat's clever, but it's not a common perspective so the behavior you propose might be quite surprising indeed. And moreover it only applies to this one particular function. The general principle still applies in general.
- IshKebab 1y ago> clamp comes down to sorting the three numbers and returning the middle one That is a really weird definition of clamp. I would expect to consistently get either min, max, or an error. I bet Rust doesn't use your weird idea... Yep. Fully sane implementation: https://docs.rs/num/latest/num/fn.clamp.html https://docs.rs/num/latest/num/fn.clamp.html
- tobr 1y agoIt’s not a definition, it’s an implementation. A definition would be something like ”constrain a number to an interval defined by two other numbers”. That happens to be identical to sorting and picking the middle value. The only difference vs OP’s clamp is that it gives a consistent and predictable result for ”inverted” intervals where min > max, instead of arbitrarily deciding how to collapse the interval.
- IshKebab 1y agoIt is a definition. You've defined the behaviour when min>max and you've chosen a weird way to define it.
- pash 1y ago> We should be able to define our functions to accept the inputs they are designed for, and not try to handle every possible edge case. Oh, look, somebody just re-discovered static typing.
- whilenot-dev 1y agoHow do you type the min > max constraint though?
- kuruczgy 1y agoWell, if your language has a sufficiently strong type system (namely, dependent types), you can take proofs of some properties as arguments. Example in Lean: def clamp (value min max : Float) {H : min < max} : Float := ...
- whilenot-dev 1y agoSure, but the author picked TypeScript nonetheless. TypeScript is not a runtime, but a mere type checker - JavaScript is the runtime and a highly dynamic language. This detail got somehow completely lost in the article, but is IMHO the main culprit why such validations aren't bad, or sometimes even preferred. The article also skipped over the following related topics: - When would you wrap errors from lower levels as your own? - What does "parse don't validate" mean when a TypeScript library gets transpiled to JavaScript?
- chongli 1y agoYou don’t need a runtime for dependent types. After type checking the types get erased during compilation.
- whilenot-dev 1y agoNobody would question that, but publishing a JavaScript library means that anyone using plain JavaScript can make use of it. Even though you aren't ever in control of the toolchain of your library's users, it's still your responsibility - as library author - to take that differences into account. If you'd transpile your library from Idris to JavaScript and publish it, these validations just can't be neglected at runtime. Type systems are just another model of the world at runtime.
- eduction 1y agoIncredibly shallow post. The level of validation and defensiveness in any piece of code will generally have to do with how close to the edge of your application it is — that is, how close to the input. Functions near the core can assume more and code less defensively than those near the edge. Libraries shouldnt be edge case first? What? /What kind/ of libraries? You really can’t imagine a library where it makes sense to code very defensively? Also the post doesn’t even use “edge case” correctly. Definitionally you can’t have an edge case before you’ve defined the acceptable input. In their clamp function the edge case would be something like a large number on the border of graduating from long to BigInt or something. Edge case does not mean invalid input. Edge case is a rare/extreme input that is valid.
- MathMonkeyMan 1y agoThis is what undefined behavior is for. You specify a contract for your function, and then the implementation of the function assumes that the contract is satisfied. It does not check, and does not try to diagnose errors. It's not about performance, it's about separating concerns: the caller handles the not-a-number case, so the callee doesn't have to. Then you add optional runtime checking of the contract, preferably in a different build mode (or a different version, e.g. "my-lib1.2-debug"), to get sensible diagnostics quickly in tests and canary deployments. The checks are redundant by definition. Defensive programming.
- sesm 1y agoAlso known as "garbage in - garbage out" approach. That's how Clojure standard library is designed.
- pwdisswordfishz 1y agoAnd C/C++.
- chowells 1y agoNow, consider that that the program might be rejected for being incorrect, without being run. Wouldn't that be even better?
- MathMonkeyMan 1y agoAll other things being equal, yes. Static types work well for constraints on function parameters. "Parse, don't validate" and all that. Some contracts are more difficult to express, though. The worst kind involve sequences of behavior, e.g. "start() must have been called," or "must have been obtained from a previous call to 'allocate()' on the same object." Even value parameter constraints can be tricky. "The input must be sorted." I haven't studied type systems, but I like the idea of values picking up attributes as they pass through functions. Imagine a "sort" function that bestows its output with the "sorted" type attribute. But then what happens when you append to that value? Is it still sorted? At some point it's convenient to be permissive with the parameter's static type and to constrain the caller with a contract.
- sebtron 1y ago> At this point, it seems clear to me we’ve just poorly designed our function. It solely exists to clamp numbers, so why would we accept strings? To me it sounds like you are using a poorly-designed language
- nenenejej 1y agoYes. Go for example doesnt need an is-nunber, nor do you need to worry about if a validation throws an exception and unwinds your call stack (or not)
- quotemstr 1y ago> To me it sounds like you are using a poorly-designed language Not language specific. A C example that comes to mind is checking every non-nullable pointer parameter in every function for NULL and reporting an error instead of just letting the program crash. (Please, don't do that: just let contract violations produce crashes.) The article's author describes a problem of experience and spirit, not a language wart.
- Turskarama 1y agoLet me blow your mind for a second: this problem is not insurmountable in language design, C is not a perfect language, and nulls are bad design.
- hnlmorg 1y agoBut the problem is literally a direct result of language wart. The nullable pointer you’ve given is another great example of language wart. And one that’s often highlighted as a specific criticism against Go lang.
- quotemstr 1y agoNo, the problem is a result of sloppy thinking --- or no thinking --- about function contracts.
- 1y ago
- afc 1y agoI wrote a somewhat related article, after running just this Friday into two blocks of code that were deliberately causing invariant violations (akin to the "max < min" situation) to be ignored silently: https://alejo.ch/3gk https://alejo.ch/3gk - Fail loudly: a plea to stop hiding bugs
- rrauenza 1y agoI think of this as fail fast. Fail immediately so its easy to root cause the failure and not have it be hidden and cause more obscure side effects later.
- moomin 1y agoProblem is, there’s a well known principle of library design: any behaviour you exhibit eventually becomes something someone relies upon. You can choose to live with silent breakage or you can validate your inputs within an inch of their lives. Next, with the best will in the world, even with a small library, you quickly discover a wide range of use cases that should reasonably be supported by your library. So all libraries end up complex, not just because of validation. Yes, static typing would help with some of this, but very much not all.
- goranmoomin 1y agoThe post is complaining about a library for a problem that javascript had 12 years ago, was not a thing for 7 years, and the ecosystem moved on. Typescript was not a thing back then. (or more exactly, it was a small thing out of the all too many transpile-to-js languages, at least) Yes, having a library named is-number looks very stupid until you look at the state of javascript in 2014. Look at issue is-number#1[0] if you’re interested. The library is-arrayish exists because array-like objects are actually a thing in javascript. About is-regexp: the author mentions that their library supports cross-realm values because it’s useful, but then says that it’s an edge case that most libraries don’t need to care about? The whole reason that the library exists is to cover the edge cases. If not needed, yes the consumers of the library would have just been using the simple instanceof RegExp check. If you’re arguing that there are consumers of those libraries that are wrong, the post might at least make sense – the presented case here is that the writer of the clamp function is stupid, not the other way around. Having a function that determines if a string is a number is not stupid; it’s importing that function and creating a clamp function with the wrong type signature part that’s stupid. Especially when it’s 2025 and typescript is universal. All of the libraries that are mentioned are like 10 years old at this point. I don’t think we have to beat the dead horse one more time. [0]: https://github.com/jonschlinkert/is-number/issues/1 https://github.com/jonschlinkert/is-number/issues/1
- throwaway290 1y ago> the presented case here is that the writer of the clamp function is stupid, not the other way around So are you saying the author updated the implementation and added deprecation warning?)) And author is not "stupid". More like "strategic". popular npm package = money. this is why everybody falls over to write leftpads and stuff.
- goranmoomin 1y ago> So are you saying the author updated the implementation and added deprecation warning? As far as I understand, the author wrote the clamp function by themselves. There is no clamp library that the author is arguing against. In fact, it seems the library ‘clamp’ in npm is a library that does exactly what the author wants – no validation, assuming that the value is a number, and just returning a number.[0] [0]: https://github.com/hughsk/clamp/blob/master/index.js https://github.com/hughsk/clamp/blob/master/index.js
- larusso 1y agoOver 10 years ago I was a bit more invested in the ruby environment and the whole duck typing thing. I really liked dynamically typed languages. One thing I remember was when learning rsync that other libraries loved to write specs where all kinds of types and values gets thrown at a function to see how it behaved. Since these languages have no compile step one needs to check how they do at runtime. I remember I picked up a pattern to check if something is looking like a string or number or can be turned into Omer etc. It definitely blows up your test specs but also makes your awesome function even more flexible for the future. Hey you never know what you throw at it tomorrow. Maybe you need to call it with an a number array in string format. I stopped doing that and concentrated to test for the types I expect. Which really breaks with the typeless nature of a language but that is more philosophical. Needless to say I think all these helper packages are way overboard. There is also the tendency under programmers to really “never repeat yourself”. Which ends up in a utility function that has to be introduced into every library or project and starts to grow because of different edge cases from all the different use-cases. Let’s add some flags and overloads. Not excepting the fact that it is sometimes cleaner to just have a copy with special adjustment of code then desperately trying to generalize it.
- zahlman 1y agoTwo common ideas I see ITT are that the problem is caused by JS not having either a) static typing or b) a large standard library. I don't understand this. Python lacks static typing, but it also doesn't have a need for the kind of type-checking that is-number and is-array perform — it's how Python's dynamic typing already works. What JavaScript is missing is strong typing: i.e. it's "fault tolerant" by performing implicit conversions everywhere and minimizing the chance of control flow ever being disrupted by an exception, presumably intended to maximize the chance that the user sees some kind of DOM update rather than the page ceasing to function. Python sidesteps these issues by just raising `TypeError` instead, and by making proper consideration of exception handling an expected part of the programmer's job. The boilerplate in TFA's opening example is essentially what the Python runtime already does. Similarly, Python has a large standard library, but it's irrelevant to the problems described. The Python standard library doesn't solve the problem of determining whether something is "a number" or "an array"; trying to use it that way does. The Python standard library doesn't solve the problem of determining whether something is "a regex"; if anything, JS' functionality here is more native because you don't need the standard library to create a regex. As for the "pascalcase" example, the standard library isn't really helping Python there, either. There are multiple third-party libraries for string-casing operations in Python; there are some things you can do first-party but they're almost all methods of the built-in string type rather than part of the standard library. Aside from some useful constants like "a string with all the ASCII letters in it", the `string` standard library implements two failed attempts at string formatting routines that weren't popular even when they did solve real problems, and a "capwords" function with subtly different semantics from the "title" method of strings. Which has existed since at least 2.0. (Granted, Python documentation has separate "library" and "language" categories, and classifies the built-in types and their methods as "library". But when people talk about the importance of a "large standard library" in a language, I generally understand that they're thinking of code that has to be explicitly pulled in.)
- Havoc 1y agoThe wild part is that a post about bloat concludes with here is more crap to install to visualize your JS stack. Starting to think that JS based front end is a trashfire top to bottom. Not this framework vs that framework...the entire thing
- meindnoch 1y agoclamp should actually accept anything comparable. E.g. clamp("foo", "bar", "baz") should return "baz".
- gourlaysama 1y agoPutting API contracts aside, the problem is also that people use a package manager as if it was a code snippet manager. As in, "how do I check if a string starts with a shebang" should result in some code being pasted in your editor, not in a new dependency. There is obviously a complexity threshold where the dependency becomes the better choice, but wherever it is it should be way higher than this.
- hawk_ 1y agoThis is the gap that LLMs have been filling quite well now in my experience. There are these little isolated tasks that are described easily in natural language for which the idiomatic code snippet can be created and importantly modified by LLMs as needed. No need to pull in pesky dependencies. Though when to switch over to a full blown dependency is still a judgement call.
- 2muchcoffeeman 1y agoThis is such a weird comment to me. These are trivial functions that could be faster to code than describe. I’d hope people aren’t relying on AI for functions as simple as clamp. I mean, people have been writing these simple functions over and over for decades when they just needed one or two things that importing a library wasn’t needed. I wasn’t aware there was a gap to be filled.
- hawk_ 1y agoNot clamp per se, but there are enough tiny snippets which can have off by one or other issues not relevant to when you think about the problem description.
- qazxcvbnmlp 1y agoI agree: Senior engineer: "you shouldn't have to use llm to do simple things" Their boss: "hey I need you to write this thing in Go for performance reasons" Senior engineer: "you shouldn't make me learn new languages, js is plenty performant for this task just install a new server. why are they making us use all these new tools? everything is new again, blah blah excuses excuses" vs. Boss: "hey can you write this in go" Vibe Coder: "write this loop to ignore the first semicolon in this response", and then proceeds to move on with life. It seems like when people evaluate the merits of what a code generation ai agent should and shouldn't do, they leave out a lot of their implicit assumptions about how project should work and their own theory of mind around coding.
- vitonsky 1y agoWell, somebody must validate data on top level. So that's fine to have packages like `is-number`/`is-arrayish` etc.
- croes 1y agoThose kind of function are like a second developer who doesn’t trust the developer of the program. Have a little faith they validate the input and give the right min and max before they call your function or let them fail to learn.
- kamma4434 1y agoI think the author has this wrong. Handling a ton of edge cases so I don’t have to do it myself is a good reason to use a library. Importing an endless tree of deps I have no control of - that is the issue.
- hk__2 1y agoInteresting but the article never takes the time to really explain what exactly is the problem with using these libraries.
- MagicMoonlight 1y agoNotice how this slop doesn't happen in real languages like C++ or Java. It's only the slop languages. You don't need a "is it a number" package in java, because the function cannot be passed a string, because it actually has a type system. All this slop has come about because meme developers refuse to accept the truth - programming languages have proper syntax for a reason.
- PaulHoule 1y agoPartially true. A lot of times you have something in Java which could be ReturnValue someMethod(Parameter p) { … var x = anotherMethodThatMightThrowAnException(q); … } and I’m going to argue that often that’s good enough but a lot of people think it isn’t so they might put 20 lines of code above that line to head off that exception or they might put it in a try-catch block [1] to respond to it or wrap it. Those unhappy paths bloat your code the same way as the guards in the blog post, make it unclear how the happy path works at a glance (place for bugs to hide in the happy path) and obviously create opportunities for bugs in the unhappy path. I’ll argue that (1) error handling is a function of the application as a whole or of a “unit of work” (e.g. database transaction) so unless you’re at the top level method of a unit of work you should “let it throw”, (2) try-finally is preferable to try-catch when it comes to cleaning up and tearing down, and (3) it is fair to wrap and rethrow exceptions if you want the unit of work manager to have more context to know what to do, or provide a better error message. In theory, you could spend time writing and maintaining error preempting and handling code and get better error messages. However that code isn’t always correct. One funny thing about AI agent programming for me is that if I ask Junie to code me some tests it works harder at testing unhappy paths than I would.
- twosdai 1y agoI feel like the type guarding programming method present in some packages, is a hangover from node js development prior to typescripts rise in popularity. So now some people just do it by habit. Honestly the only place having code like that I see being useful is at the controller level inside an api or other untrusted input validation for an application.
- dccoolgai 1y agoAlways interesting to think about Postel's law in the context of these kinds of things. ("Be liberal in what you accept and conservative in what you send")
- pizlonator 1y agoIt’s interesting how multiple of the bad cases the post identifies exist because of how gross the dynamic types in JS are. If JS’s dynamic types worked like Ruby’s or Python’s then you wouldn’t think to build a library that tells you if something is a regex.
- rossant 1y ago> I don’t really agree with this and think downloading a package for #! 86 million times a week is a bit much. Yeah. A bit.
- minaguib 1y agoEntirely unrelated to the topic, but my mind was blown when I recently learnt that clamp() can be implemented via .median(val, low, high), and the param order doesn't matter!
- darepublic 1y agoFwiw in the example of guaranteeing number type a simple typeof number is sufficient.