Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, by taking care of all the exception handling these packages do. It's why these stupid packages exist: because the standard library doesn't handle them.


This approach is called “garbage in - garbage out”. The idea is, you can add extra checks and sacrifice some performance. But if checks are built in there is no way to remove them, even if you don’t need them and they hurt performance. Clojure’s standard library uses “garbage in - garbage out” approach too.


> But if checks are built in there is no way to remove them

Sure there is: you have a compiler which recognizes uses library functions and makes code generation decisions based on whatever information is available at the call site.

And this is easier to do for built-in functions, whose definition you can assume from the spec.

The simplest example is constant folding. If isEven is part of the language, a compiler can constant-fold isEven(0) to true even if no inline definition of it is visible.


That’s interesting. How does compiler know that some piece of code is a removable check?


That kind of "exception handling" is what I use Typescript for. JS decided back around ES4 that type hints were too complicated for browsers and they've been left to outside tools like Typescript and Flow.

I'm not always sure that was the right decision long term, but that was an informed decision of the time.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: