News for hackers. Stuff that matters.
Re:JavaScript libraries should be written in TypeScript by partycoder on Wednesday March 16, 2016 @12:30PM (#11298570)
Defensive coding in JavaScript? That's absolutely not how most libraries are implemented.
Re:JavaScript libraries should be written in TypeScript by hipsterrific on Wednesday March 16, 2016 @12:39PM (#11298629)
If you're expecting one type and get another, you have to handle it, right? Documentation is important in JavaScript by virtue that code contracts are never enforced due to implicit typing.
Re:JavaScript libraries should be written in TypeScript by partycoder on Wednesday March 16, 2016 @12:43PM (#11298669)
JavaScript makes this process optional, and it only needs to go wrong once to become a problem.

Personally I saw over a million dollars lost and an entire team laid off after a piece of code started working with a value that was expected to be a number but wasn't.

Re:JavaScript libraries should be written in TypeScript by nly on Wednesday March 16, 2016 @01:12PM (#11298924)
> If you're expecting one type and get another, you have to handle it, right?

Depends. You could debate the same philosophy wrt C and null pointers. Should you check all your arguments to see if they're null, if the documentation/specification says they should never be null, or accept undefined behaviour and segfault?

In practice, most code assumes everything is checked, sanitized and used correctly at the outer most API boundary.