| I'd argue that it's not exactly "better", but more that it just makes different tradeoffs. Using a full well-written* dependency for something not part of your "core competency" (even something seemingly trivial) is often a better choice in my opinion. That dependency will often know the "unknown unknowns" to you since their "whole purpose" is solving that one issue. In this case, and from what I can see from my VERY small glance at the code, I'd argue using a polyfill would be a better choice in this situation. The polyfill has cross-browser tests, ensures compatibility, continually tests against new browser versions and will alert you and shield you from things if they change, download size is less of a worry for extensions and most of it no-ops away in 100% supported browsers, and it's maintained by mozilla. Obviously there might be additional reasons why the uBlock origin developer isn't using it, it might be super overkill for his needs, he might consider the browser API part of his "core competency" and therefore shouldn't be relying on 3rd party code for it. I'd trust him more than myself here since I know so little about the domain. And I had a similar question to the GP commenter of why he decided to avoid the polyfill. Your little saying isn't a useful answer, and the dig at "modern javascript developers" is not only unnecessary but also a real annoyance for me because it's used to dismiss just about every opinion while providing no real reasoning why you think that way. If you think a little copy is better, explain why! Don't just put down a group and leave without giving out any useful information! * A "well written" dependency meaning something well tested, has a solid development team or dedicated person, and has somewhat widespread usage. Obviously it will differ depending on your needs. |
Yes, it makes tradeoffs that are different, and those tradeoffs are different in that they're better. Often, not always. That's the statement in a nutshell.
> Using a full well-written* dependency for something not part of your "core competency" (even something seemingly trivial) is often a better choice in my opinion.
If it's outside your core competency, you can't really judge if a dependency is well-written. Popularity is an entirely unreliable quality metric. "Well-tested" also means nothing, a lot of people write completely useless unit tests but still fail on integration. How much time are you going to spend researching and vetting the code and the development "team" for that "seemingly trivial" dependency? How about writing a few lines of code and building a little bit of understanding instead? You can still use other people's code as a reference, even copy parts of it.
> That dependency will often know the "unknown unknowns" to you since their "whole purpose" is solving that one issue.
Sure, a few lines of code may have unknown unknowns. You know what else has? Other developers. Unbeknownst to you, "the team" could be the left-pad guy, who turns out to be "political". "The team" could be the guy that just hands over an unmaintained repository to a cryto-thief from China. That one took several weeks to get noticed by the community.
You start with one little dependency for one use-case, you end up with hundreds if not thousands of dependencies. You realistically have no capacity to deal with this in a diligent manner.
One could argue that by using "modern Javascript" with its pathological reliance on micro-dependencies, one has already given up control to the hive of random developers anyway, so one more dependency wouldn't hurt. I probably would agree with that. That doesn't mean every Javascript program would be better off this way.