Everybody understands the purpose of libraries and no one is going to reinvent something major from scratch – but the problem is in simple stuff that gets you in trouble.
Because no one is going to rewrite Express and React in JavaScript, or Scikit-learn and Matplotlib in Python.
BUT
How about a simple sorting algorithm?
In JS it would look something like this:
[3, 1, 2].sort((a, b) => a - b);
// output: [1, 2, 3]
Or you can just use Lodash:
_.sortBy([3,1,2]);
// output: [1, 2, 3]
Using Libraries For Simple Tasks
These two examples above look very similar. And amateurs could argue that it’s all the same whether you use the library or not.
BUT
It’s not the same.
MISTAKES ARE HARD TO DETECT
In the example above it is easy to make a mistake and switch the places:
“b – a” vs. “a – b”
On the other hand the function sortBy is very hard to miss and if you misspell something you will get a very obvious error.
LIBRARIES ARE TESTED
It is unlikely the (Lodash) library function sortBy has an error. There are tests written for it, as well as big community that makes sure everything works ok.
A single programmer (especially junior who engages in reinventing the wheel) is more likely to make a mistake when re-implementing the sort algorithm.
And this makes the entire code less readable, more complex, and less reliable.
FUNCTIONS ARE GENERALIZED
What if your array didn’t contain plain values but objects instead?
Now you’d have to develop a separate sorting object and suddenly your simple solution is getting more and more complex.
With even higher chance of making an error.
Instead you can just sort array of user objects by their name like this:
_.sortBy(users, ['name']);
Libraries Make You More Productive
In short, libraries make you a better developer.
Also, they make you a more productive developer.
And productive developers have higher salaries.
So remember that the next time you feel the urge to implement some “simple” algorithm yourself.
P.S. -> read this article if you want to double your salary