3 ms·
>Also the code is faster, likely because it doesn't have to load another module at runtime. Sure, but common sense would guide programmers about such tradeoffs
by jasode 11y ago
>Also the code is faster, likely because it doesn't have to load another module at runtime.
Sure, but common sense would guide programmers about such tradeoffs. The extra time spent loading an additional library dependency would be amortized over the total execution time of the program -- IF -- the program makes repeated use of the library.
If a js file only has a single getElementById() call, substituting that with a JQuery library to get the "$" syntax would be overkill.[1] Howevever, if the javascript has many complicated DOM selects and bunch of animations, the extra JQuery load time can be justified.
One of the reasons to use a library the author didn't touch on was "insurance against unknown edge cases." For example, I could attempt to write 50 lines of code to uppercase a lowercase Unicode string. However, my attempt would have bugs in it. Instead, it would be more prudent to use the ICU library. It's a hassle to add that dependency and it's many thousands of lines more than my "simple" program but the ICU developers covered more edge cases than I ever thought of.
[1]http://www.doxdesk.com/img/updates/20091116-so-large.gif http://www.doxdesk.com/img/updates/20091116-so-large.gif
- arielb1 11y agoCertainly they may have covered many edge cases, but they may have covered them in a way that interacts poorly with your program. Unicode uppercase to lowercase is ill-defined enough there is no single good solution.
- zensavona 11y agoRelated: What is the best number? Where are my legs?