Please, do not install every shit
juffalow.com
juffalow.com
When working with Node.js or JavaScript in the browser, there's often a huge number of modules available. But even though there may be six different modules trying to solve the same problem, every one of those modules may be incomplete.
When working with Ruby on Rails, I find that regular Ruby gems are pretty safe. There's often one or two popular, well-maintained solutions to a common problem, and I'd be fool to reinvent the wheel. However, gems which extend Rails itself can be more problematic, and they often break during major Rails upgrades.
Rust crates have a few nice properties: The Rust language itself has near-flawless backwards compatibility, Rust crates are immutable once published, and almost everybody uses semver. Oh, and cargo is great at managing dependencies. What this means is that it's often worth depending on very small libraries. Sure, maybe it's only 30 lines of code, but it's the right 30 lines, thanks to a process of refinement and to PRs from several people.
So the exact trade-offs here vary considerably, depending on the details of a specific ecosystem and its tools. I do agree that for browser-based stuff—especially if you're targeting evergreen browsers—that it's often better to write a few lines of code yourself than to add a badly-maintained dependency.
A bad behaving dependency (has useless deps) doesn’t invalidates the whole idea of using a package manager.
Probably the author has not enough experience in maintaining projects written by smart people where they write by themselves all the collateral parts.
Using dependencies extends the “standard” library so that it increases global (extra team, oss) reuse and the probabilty to find something “known“ in your next project.
Could be wrong, in that case I’ll stand corrected.
I am blocking Javascript vigorously allowing the occasional first party script, if I really value the site. If you throw me into a vicious cycle of forcing me to allow more stuff at each cycle, I go away, especially on retail sites.
Currently, the best malware protection is to switch Javascript off. Every user understands the consequences of crypto malware. Therefore...
If you throw me into a vicious cycle of forcing me to allow
more stuff at each cycle, I go away, especially on retail sites.
Avoiding dependencies to capture the 0.01% long-tail of users that heavily block JS seems like a massive waste of time for anybody but the most specialized of retailers - especially since those abandoned visits aren't going to show up in anybody's analytics...I assume that most people around here are pretty good multipliers.
Their colleague's version of the task however will simply require to update "react-scroll-to-component" to get new fixes. The component has a few closed issues and some opened ones. As there is community activity on it, they might as well leverage it.
Any new developers on their team will simply need to read the repo's documentation and examples. I doubt their version is documented.
The package "react-scroll-to-component" also has the advantage of living in the react's ecosystem. It isn't a few line of hack'ish Javascript but an actual component that you can configure in a React application. Any next places they will need to add scrolling behaviors will be an easy job. His snippet however will require playing in the source JS over and over again.
While I agree that "INSTALL ALL THE THINGS!!!" is a bad philosophy, in this case I agree with their colleague. That component only has a few dependencies and add pertinent features to the project.
Because the latter is so much more productive, I think the real question is, how do we manage the undesirable side-effects of the package-for-everything model?
I see the major concerns as:
- Potential security problems that evolve over time.
- Reduced understanding of how the underlying code works.
- Reduced mental clarity of how the project as a whole works.
- Non-traditional approach to debugging. (Dig through foreign code, post GitHub issues.)
- Artifact size / performance / power consumption issues.
I'm curious about novel approaches to help manage these concerns.
The "grownup" companies I've worked for either explicitly ban or discourage "Programming by copy/paste from the Internet" and have review processes to gate inclusion of 3rd party code so that the licensing can be reviewed.
Licensing issues aside, 1. as a tech lead, I would feel obligated to act as the gate for bringing 3rd party dependencies into the project, and 2. if you cut paste code into my project, then during code review, you should be able to explain in great detail what it does. If you can't, it gets reverted.
When I created a hello world app in React, it took what felt like several minutes to pull down what seemed like hundreds of dependencies. My uninformed opinion is that the standard operating procedure in Reactland is to pull in "well tested" dependencies, where "well tested" means "downloaded a lot" and you hope the two are correlated.
I don't know if there's a real "standard operating procedure" or not, but it seems to me that it's the responsibility of each project maintainer to evaluate the fitness of a particular dependency for that project.
Just like with every package manager that I've ever heard of, you're responsible for what you install. I'm sure you can get buggy packages with poor test coverage via apt-get install / brew install / gem install / whatever-else install.
Everyone's experience is different, mine, in this case, has been the opposite.
Library/package breakages caused by browser updates often take longer for the maintainers to release fixes for than I'd like to wait. I can fix myself and submit PRs, but this takes orders of magnitude more effort than fixing a similar thing in a library you wrote yourself; you can't be familiar with the internals of every external dependency, particularly as they're often generalised and therefore larger and more complex than if you write them yourself for specific functionality.
There's a trade-off of course, but I'd definitely consider updating libraries in response to browser update breakages a "con" when listing the pros and cons of using external deps.
That's how you evolve open source projects. If everyone were to simply copy paste snippets in their projects for fear of library rot, every library would rot.
> Fork, understand, fix, create PR
That 2nd step is more time-consuming for some dependencies than others. I'm a strong proponent for understanding how your dependencies work, but there are always limits to the depth of knowledge of the internals of every one.
If you do a lot of scrolling into various components on various actions on your page, this module can sure be handy. Otherwise, it doesn't really seem to do anything better than a simple snippet copy'n'pasted into proper place. Those "non obvious at first cases" in this case seem to be mostly about how developer uses it in their code, so if you just use it in one place to do one specific thing, there are none.
[edit] Oh, sorry! I saw "react-scroll", while the article mentions "react-scroll-to-component". This one actually consists of 32 LOC and there's nothing more to it! It depends on "scroll-to", which is 66 LOC, but most of it is due to formatting and API and could be probably squeezed into a few lines without losing much clarity. Then it depends on a "tween", which actually does the smoothing and could be the one thing actually worth depending on, if that's what you need to achieve. In simplest cases it boils down into a one-liner as well, but it's a well-known library anyway.
"scroll-to" also depends on "raf", which is a polyfill you might or might not need.
Watch out for actively developed dependencies.
"A little copying is better than a little dependency."
https://www.youtube.com/watch?v=PAAkCSZUG1c&t=9m28sWhat is to be avoided is inclusion of packages that implement a ton of functionalities, and then only using a very small subset of those. In these cases it's better to create your own solution.
what's the better way to do it
copy & paste, or use a package manager
When you add a dependency, how do you prevent the maintainer of the dependency or any sub- or sub-sub-...dependency to break your system in the future?I can't imagine any big companies work like that. Execute code on their servers which is under the control of 'somebody from the internet'.
I can not imagine that the security of Facebooks servers is at the mercy of a chain of anonymous coders.
That sounds like a lot of work. Compared to copying/writing 30 lines.
How do you know the pinned version and it's dependencies do not get changed by the maintainers?
Unfortunately it seems that people with my mindset towards dependencies are a dying breed.
Because it's nice to not have to write every bit yourself and end up with your own package manager anyway. (e.g. I'm not going to rewrite a ProtBuf lib for each project, I'll reuse my same code, but want to propogate update and bug fixes between projects.)
I'm less annoyed by libraries and package managers and more annoyed by "libraries" like leftpad and package managers like....well, most package managers. Here's hoping Nix or an intellectual decedents take hold and become more useful and universal. (OK, OK Cargo and RPM aren't that bad. Apt is OK, but too often leads to inconsistent states.)
I think package managers have made things much worse, because if you're going to have dependencies you shouldn't have such a complicated relationship with them that you need a tool like a package manager to deal with it, but package managers encourage that behavior. I don't think we should need things like Nix just to be able to put together a stable and consistent system.
Then use the package.
<a href="#section-1">Go to section 1</a>
<section id="section-1"></section>"Can we make it scroll to section 1 slowly, so the user sees what's going on?"
"The heading of section 1 gets covered by the sticky top menu bar, change it so scrolling places section 1 just below the sticky."