by potatoz2 · 4y ago · 0 comments
The DOM though is definitely complex and built of accretion over time. The Web resists refactoring because we can’t break websites from the 90s.
I agree; it's a plague all dynamically-typed languages face. I've yet to meet one that doesn't hit me with some kind of powerful pain-in-the-ass corner cases as a trade-off for the power of its terseness.
I fell in and out of love with Python over the course of a decade or so. Initially very excited about doing so much with so little code; fell out of love when I used it in an industry setting and realized 100% unit test coverage was mandatory because the lack of variable declaration means every line of code is a potential runtime error in waiting due to a simple name typo.
There's just no way to know that `if foo:` doesn't reference a foo that's supposed to be on the global scope.
(Contrast JavaScript, where `use strict` was added to force explicit reference to non-local scope).
You can explicitly mark a nonlocal or global as well.
Now if your project needs to be impervious to malicious actors, additional safeguards will be needed. But I’ve never encountered this situation in a long career.