News for hackers. Stuff that matters.
Re:Why I often implement things from scratch (2006) by seisvelas on Sunday March 08, 2020 @11:14AM (#22518393)
Okay, you got me. I am in the camp that says calling the library is (in the general case) obviously the better choice.

My (camp's) reasoning:

1. Your handrolled solution is likely worse than the library anyway

2. You're wasting effort reinventing the wheel

3. You risk adding unnecessary opacity by littering the program with dense math

4. Other programmers will assume there is a pertinent reason you handrolled the algorithm instead of using the library. Now everytime someone touches that code they have to reverse engineer your approach to see what it does different from the library such that you had to roll it yourself (surprise: nothing!).

The two exceptions I imagine are 1) if you really do absolutely need some slightly modified microoptimization of what the library does or 2) if you are working for a platform where there is good reason to avoid even slight bloat (embedded).

For the people who read OP's comment and believe I am (obviously) wrong, what is your camp's way of looking at this?

Re:Why I often implement things from scratch (2006) by throwsprtsdy on Sunday March 08, 2020 @11:39AM (#22518545)
> Your handrolled solution is likely worse than the library anyway

This assumption led to a lot of O(n^2) left-padding happening over the years, via left-pad from node.js.

Ideally libraries would be well-tested and of high quality, but at this point there may be too many of them to vet.

My own 2 cents is that if it's easier to implement the code from scratch than to evaluate and choose a library, perhaps the invent-it-here choice works best.

Re:Why I often implement things from scratch (2006) by danShumway on Sunday March 08, 2020 @12:01PM (#22518693)
Parent's comment is getting downvoted to all heck, but it is completely, obviously true in the Javascript ecosystem. If you're a competent-to-expert Javascript programmer, you will regularly run into libraries that are not coded to your standards.

And honestly, even throwing those libraries out, it's sometimes not even a question of doing a "better" job than the library. The library is designed for general-use, but my needs aren't always general-use. Sometimes libraries are good, but they're wasting time on stuff that I don't need.

This is the reason why every Unity game on the web takes 4-5 seconds to load, and my custom engine takes on the order of milliseconds to load. It's not because I'm a better programmer, it's not because Unity devs are crap, it's purely because I know exactly what my engine needs to do, and I don't waste time on anything that it doesn't need to do.

I can think of tons of examples where I've started out using an existing library and then realized that getting rid of abstraction made my code faster and easier to debug. Heck, I can think of tons of times where I've privately forked libraries and deleted codepaths or rewritten algorithms to make them more efficient for my use-cases. There are very few JS libraries that I regularly use where I have not at some point needed to care about their internals.

And I am definitely not a crazy, insane, masterful programmer. If I'm occasionally circumventing d3 internals or doing stuff manually, it's not because I'm special. People have this assumption that if something has a bunch of stars on Github, there's no way they could possibly code something more appropriate or efficient, and for a lot of people, that just isn't true.

Re:Why I often implement things from scratch (2006) by Paperweight on Sunday March 08, 2020 @03:27PM (#22519973)
"Surely this core cryptography library with 21 contributors and led by a superstar Node.JS dev with 9+ million weekly downloads and 1000+ dependants will be a great example to read and learn from..."

Opens source code.

Closes source code.

"Well, looks like I'm going to be a Rust developer from now on."

Re:Why I often implement things from scratch (2006) by NohatCoder on Sunday March 08, 2020 @04:25PM (#22520368)
Just don't ever look into the crates, as long as the lid stays on the crates are perfect, no reason to believe otherwise.
Re:Why I often implement things from scratch (2006) by slavik81 on Sunday March 08, 2020 @04:27PM (#22520382)
I had the same experience, but I tried to help. Now my name is in the contributors list, but I still don't trust it. My changes have all been lost to rewrites, and I assume new bugs have replaced the old ones I fixed.
Re:Why I often implement things from scratch (2006) by alfiedotwtf on Sunday March 08, 2020 @09:51PM (#22522216)
Thanks for saying this. I’m in this camp too.

... but I think the majority are in the “I just need shit to work and develop fast” camp, and don’t care if it’s not optimal, so they can finish their current project and move on.

Re:Why I often implement things from scratch (2006) by ulucs on Sunday March 08, 2020 @01:30PM (#22519258)
That’s just wrong. JS uses ropes for the string implementation, so even the inefficient left padding is O(n).
Re:Why I often implement things from scratch (2006) by throwsprtsdy on Sunday March 08, 2020 @03:38PM (#22520050)
You're right. I'd correct my original post if I could. I stand by my point but I chose a terrible example.
Re:Why I often implement things from scratch (2006) by jackcviers3 on Monday March 09, 2020 @08:34AM (#22524843)
That's because Node and JS are geared towards software engineers new to the field. The ecosystem is geared towards delivering things quickly and cheaply. Like most things, that will work 80% of the time. Most projects are shacks, not skyscrapers.

The problem is, 20% of projects are skyscrapers, and you can't build those out of pine. Sometimes, you can't build them out of standard steel and rear. You actually have to pick the correct raw materials, create a stable and maintainable architecture, adhere to strict regulatory standards, and use advanced tools to create a working edifice.

The software industry's current practices have encouraged a one-size-fits-all mentality, and that just means that it's almost time for another SLDC paradigm shift to swing the pendulum back the other way to achieve balance. It will happen, be patient.

Re:Why I often implement things from scratch (2006) by jolux on Sunday March 08, 2020 @11:48AM (#22518608)
If you're better at this than LAPACK to the extent that you do not even trust it to function correctly, more power to you.
Re:Why I often implement things from scratch (2006) by throwsprtsdy on Sunday March 08, 2020 @11:51AM (#22518625)
My point is not that I'm better at it than some specific library, it's that choosing a library would take more effort than writing some straightforward code.

EDITED TO ADD: In fact getting LAPACK into the build if it's not already there is more of a maintenance imposition than just writing a couple of lines of code for this.

Re:Why I often implement things from scratch (2006) by jolux on Sunday March 08, 2020 @01:36PM (#22519290)
Not if there already exist bindings in your language, which is the case more often than not these days.
Re:Why I often implement things from scratch (2006) by BubRoss on Sunday March 08, 2020 @11:54AM (#22518653)
I'm not going to integrate LAPACK for a single line expression.
Re:Why I often implement things from scratch (2006) by jolux on Sunday March 08, 2020 @12:20PM (#22518834)
LAPACK is the underlying library behind most linear algebra packages in other languages and furthermore it was just an example. My guess is that you probably don’t have just one line of matrix manipulation ever, in which case using a well established library is a good idea. If not, then sure. Do it yourself. But that’s still more code that you have to maintain now.
Re:Why I often implement things from scratch (2006) by username90 on Sunday March 08, 2020 @12:57PM (#22519060)
> But that’s still more code that you have to maintain now.

10 lines of code is easier to maintain than a whole dependency.

Re:Why I often implement things from scratch (2006) by jolux on Sunday March 08, 2020 @01:18PM (#22519194)
That's arguable, because 10 lines of code almost never just stays 10 lines of code, and my point in the first place was more contesting that the dependency is hard to choose, or that there aren't solid proven libraries for this.
Re:Why I often implement things from scratch (2006) by jlokier on Sunday March 08, 2020 @02:35PM (#22519675)
A counterargument:

1 large, complex dependency (plus the 20 lines of wrapper code to transform your program's internal data to initialise and call the library) almost never just stays as 1 large, complex dependency (plus 20 lines of ...).

Re:Why I often implement things from scratch (2006) by jolux on Sunday March 08, 2020 @05:54PM (#22520875)
If you're truly just doing a 2x2 matrix manipulation once in the codebase, then I concede. I guess I'm blanking on situations where that would be the case though, or where more generalized capabilities wouldn't be useful.
Re:Why I often implement things from scratch (2006) by jlokier on Sunday March 08, 2020 @10:50PM (#22522532)
That's fair enough.

But I was really just wanting to show, via irony, that the structure of the original argument is self-annihilating.

That is, "X almost never stays as just X therefore X is bad" applies to both branches reasonably, and is therefore invalid as an argument in support of one branch.

Re:Why I often implement things from scratch (2006) by sagichmal on Monday March 09, 2020 @05:54AM (#22524178)
> If you're truly just doing a 2x2 matrix manipulation once in the codebase

That is the precise premise of the hypothetical.

Re:Why I often implement things from scratch (2006) by jolux on Monday March 09, 2020 @09:04AM (#22525008)
In fact it was not presented with that level of precision, it merely asked if one had to solve that particular problem and gave no indication about what other algorithms and manipulations the codebase might be using. And furthermore, I maintain that the original example is contrived until proven otherwise.
Re:Why I often implement things from scratch (2006) by kqr on Sunday March 08, 2020 @04:57PM (#22520569)
This is why it's important to add a comment to those 10 lines describing the choice, and urging future contributors to reevaluate the situation.

(Of course, one should always reevaluate the situation when making changes to code, but we all need a nudge sometimes when we're afraid of doing the wrong thing.)

Re:Why I often implement things from scratch (2006) by jolux on Sunday March 08, 2020 @06:55PM (#22521232)
Now that, I can wholeheartedly agree with :)
Re:Why I often implement things from scratch (2006) by username90 on Sunday March 08, 2020 @01:37PM (#22519305)
> 10 lines of code almost never just stays 10 lines of code

This is only true when you implement business logic, not when you implement algorithms.

Re:Why I often implement things from scratch (2006) by jolux on Sunday March 08, 2020 @02:02PM (#22519483)
The difference between those two things is often blurry from a distance. Business logic is algorithmic too, it's just a question of how specific and complex the algorithm is.
Re:Why I often implement things from scratch (2006) by username90 on Sunday March 08, 2020 @02:10PM (#22519521)
Business logic changes and grows more complex over time, how to invert a matrix doesn't. Trust me, I implement algorithms for a large library for a living, they very rarely change or grow.
Re:Why I often implement things from scratch (2006) by jolux on Sunday March 08, 2020 @05:43PM (#22520816)
I’m aware that you have a definition of “algorithm” that only includes things that don’t change, and I think I know roughly what you mean, but also algorithms are pretty much unavoidable in line of business development. Whether or not they’re well defined, sufficiently general, and have a good name is another thing. In this case you’re right but in a codebase with no documentation where people are doing things like re-implementing JSON parsers from scratch, as I was stuck with at my last job, I’m very wary of “this algorithm is simple” because I don’t trust my coworkers in that case to actually know what they’re talking about. I’m completely sure you do, for what it’s worth.
Re:Why I often implement things from scratch (2006) by BubRoss on Sunday March 08, 2020 @02:54PM (#22519784)
Not really, the individual STL algorithms haven't changed. Partition is still a one line loop. Some things can be left alone.
Re:Why I often implement things from scratch (2006) by jolux on Sunday March 08, 2020 @05:50PM (#22520862)
In this specific instance, sure. I'm talking about business logic in the general case.
Re:Why I often implement things from scratch (2006) by BubRoss on Monday March 09, 2020 @12:29PM (#22526695)
You're the only one talking about business logic. By definition business logic is not the same as fundamental algorithms or mathematics. Inverting a matrix doesn't change.

A business wants to be able to change its logic to evolve how they do things. You keep trying to conflate these things but they are polar opposites.

Re:Why I often implement things from scratch (2006) by jolux on Monday March 09, 2020 @06:22PM (#22530544)
What definition are you going on exactly? Nobody has said the phrase “fundamental algorithms” before you in the thread. Yes, I would agree that those are distinct from business logic. Nonetheless the actual definition of the word “algorithm” is not formally or universally agreed upon at all. I’m curious what definition you’re using and where it came from, if only because I now feel confused.
Re:Why I often implement things from scratch (2006) by BubRoss on Tuesday March 10, 2020 @12:46AM (#22532796)
When something doesn't need to change, that's at least an established algorithm. Algorithms like sorting, partitioning, hashing, reduce, map, swap etc. are common and don't change. Mathematics like linear algebra don't change. They are fundamental elements of most nontrivial programs.
Re:Why I often implement things from scratch (2006) by jolux on Tuesday March 10, 2020 @07:39AM (#22534560)
Sure, that part I agree with. But the stuff around it, i.e. how those fundamentals are used and composed, also qualify as algorithmic to me. It’s probably a lower-level definition than you’re using, because to me all programs are an algorithm of some kind.
Re:Why I often implement things from scratch (2006) by BubRoss on Tuesday March 10, 2020 @09:07AM (#22535073)
I don't know what you are trying to say at this point. You were arguing that every part of a program changes and expands. It should be pretty clear that that is not true.
Re:Why I often implement things from scratch (2006) by NohatCoder on Sunday March 08, 2020 @04:52PM (#22520537)
1. The computation is a handful of simple arithmetic statements, there is almost nothing one can do to optimize those. The library is likely written to handle inversion of any size matrix, that means it adds a bunch of control code to be more general, but also slower for this case.

2. You are wasting effort evaluating libraries. And I wonder what you lose in compile time?

3. You are calling into a black box, and you talk about opacity, a simple comment: /* this inverses the matrix */ will deal with your perceived issue.

4. Other programmers will assume there is a pertinent reason you included yet another dependency. Wonder what it does that 5 lines of code couldn't have done (surprise: nothing!).

Re:Why I often implement things from scratch (2006) by SilasX on Sunday March 08, 2020 @06:19PM (#22521013)
>The computation is a handful of simple arithmetic statements, there is almost nothing one can do to optimize those.

I'm not sure that's right in this case. For inverting a matrix, it makes a huge difference whether the determinant is exactly zero or just very close, and (IIRC) floating point math may give the wrong answer. A library will have worked through this issue.

Re:Why I often implement things from scratch (2006) by rzwitserloot on Sunday March 08, 2020 @07:24PM (#22521420)
The history of various bugs in various very commonly used libraries, with them being extremely obvious after being discovered, strongly suggests this:

If there is some situation that is somewhat likely to come up and needs special code, but it is not immediately obvious (and, going by OP's evident lack of realizing it, that's some proof to say it is not immediately obvious)? It may not be there. And even if it is the common path, it can still be buggy.

Is is less likely that a library with some actual use out there has these bugs vs. handrolling it, but, if you handroll it, you're writing it for _your_ case, specifically with what you have in mind, whereas the library is more general than that. That's usually upside, but there's also downside, in what may be obvious to your usecase may not be obvious to the library.

The central point of the top comment here, that opinions differ and that there isn't actually an obvious answer even if you think there is one, holds true here.

Re:Why I often implement things from scratch (2006) by NohatCoder on Monday March 09, 2020 @04:14AM (#22523798)
You have already got floating point inaccuracy on the input, even if the library somehow avoid inaccuracy when computing the determinant, it can't tell the reason for a zero or almost-zero arising. What is the library supposed to do? You will have to deal with the issue of either a very big numbers matrix, or no matrix at all, in any case.

This is a great example of the fallacy of believing that a library automatically solves arbitrary issues.

Re:Why I often implement things from scratch (2006) by SilasX on Monday March 09, 2020 @07:59AM (#22524674)
>You have already got floating point inaccuracy on the input,

Not if they come in as integers that have to be coerced at some point.

>What is the library supposed to do?

Compare ad to bc instead of ad - bc to zero, for one.

>This is a great example of the fallacy of believing that a library automatically solves arbitrary issues.

I didn’t say that and don’t believe it. My point only depends on he library having avoided more domain-specific rookie mistakes than I would have caught in five minutes, when it comes to computational linear algebra. Like the sibling commenter, I don’t think libraries are a panacea, and the answer depends on the specifics of the case.

Re:Why I often implement things from scratch (2006) by NohatCoder on Monday March 09, 2020 @02:52PM (#22528465)
>Not if they come in as integers that have to be coerced at some point.

In which case you can calculate the determinant exactly with your own roll, but a library will likely force you to convert everything to doubles.

>Compare ad to bc instead of ad - bc to zero, for one.

That is the same thing, a compare instruction is basically just a subtract that doesn't write the output, so you get zero/equality in exactly the same cases. Most compilers will probably turn your code into doing just one subtract and then check the flags, no matter which version you write.

Re:Why I often implement things from scratch (2006) by mrighele on Sunday March 08, 2020 @06:28PM (#22521064)
I used to be in the "implement from scratch" side, but these days my position is a lot more "it depends".

My approach to deciding if using an external library or write the code goes more or less as follows:

a) Limit yourself to a few big libraries that are widely used and well supported.

Especially if you work with a language where it is trivially easy to publish a new library, let's say javascript, you will find that even if you are just an average programmer half of the libraries you have access to have worse code that you would have written (so your point 1. is not necessarily correct)

Also using a library has a number of costs with it: increase in code size, time wasted updating it when needed, learning how to use it, understanding its documentation (if there is any at all), understanding why it doesn't behave how it is supposed to, checking github for bugs not yet fixed, etc. (so the effort spent in your 2. point is not necessarily bigger)

This cost is reduced is the library is a quality one, and also if you use a good amount of it, so my second point is

b) try to avoid a library if you just you need to use little of its functionality

Not only it may be cheaper to re-implement the part that you need, but adding a whole library means that you give charte blanc to other developers to use all the other parts of that library. This may be something that you want to avoid, expecially if the library has varying quality and not all parts are well-written. On the other side, if you know that you will probably need other parts in the future, it may be better to use the library instead.

My third rule is

c) keep in mind your team

If most people in your team already know a library, the cost of using it is greatly reduced. On the other side, if it new for most of them, it may be easier for them to maintain custom code (relates to your point 3.).

Re:Why I often implement things from scratch (2006) by enriquto on Sunday March 08, 2020 @11:24AM (#22518450)
> I am in the camp that says calling the library is (in the general case)

You misunderstood the question. The question is not about the general case. It is about solving a linear system of two equations and two variables. The solution is not found by "an algorithm", it is a simple formula that fits in one line.

Re:Why I often implement things from scratch (2006) by crispyambulance on Sunday March 08, 2020 @03:43PM (#22520079)
Sure, if you're solving a 2x2 in ONE place in a piece of software, it makes sense to just perform the computation directly without using a library.

Realistically speaking, though, if you're doing one 2x2 computation, you're probably going to end up doing a bunch of other linear algebra as well. If you don't do linear algebra in your everyday work, the threshold from rolling-your-own solution to grabbing a library is going to come up very quickly.

The Armstrong example is perhaps a bit mis-titled. He's talking about "implementing from scratch" only insofar as he can use the facilities of his platform to perform exactly the task he needs to do rather than bringing in a huge dependency, in this case, an FTP server that does a lot more than the one task at hand.

Re:Why I often implement things from scratch (2006) by NohatCoder on Sunday March 08, 2020 @04:56PM (#22520563)
If you don't know how to do linear algebra, a library is unlikely to help you. Rote stuff like matrix inversion is the easy part, figuring that that is what you need is where things tend to get hairy.
Re:Why I often implement things from scratch (2006) by crispyambulance on Monday March 09, 2020 @08:55AM (#22524961)
I think also that people can "know" linear algebra but not be skilled it's practical implementation and usage in software. That's partly why computation libraries are among the longest-lived pieces of software in existence.
Re:Why I often implement things from scratch (2006) by SilasX on Sunday March 08, 2020 @06:15PM (#22520993)
I hate to nitpick like this, but...

The question asked about inverting a 2x2 matrix, nothing about solving a linear system of equations. The latter is certainnly one common use of inverting a matrix, sure, but from the problem as given, the use-case could just as well be "report to the end user what the inverse is".

Re:Why I often implement things from scratch (2006) by heisenbit on Sunday March 08, 2020 @12:04PM (#22518715)
I was tending to go in your direction, but then the formula contains a division and we could be faced with a division by zero error. Which makes me a bit uncertain whether it is so simple. If we are guaranteed the matrix is invertible then doing it by hand is something I would prefer. And likely if it is not then as well since...

The invertibility issue also plagues any library and while it may not blow up by a division by zero we likely still would need to handle that case. This requires to understand the libraries handling of corner cases and how it affects the results.

Re:Why I often implement things from scratch (2006) by ci5er on Sunday March 08, 2020 @09:06PM (#22522001)
And, now, we know why we have an explosion of libraries that do the job badly OR end up with bloated binaries by including LINPACK when a one-liner would have done the trick.

You triggered a conversation thread that made me understand the ecosystem dynamics a bit better. Thank you.

Re:Why I often implement things from scratch (2006) by bryanrasmussen on Sunday March 08, 2020 @11:41AM (#22518562)
1. If you were Joe Armstrong or at his level, probably not.

2. If you're Joe Armstrong the amount of time you're wasting is negligible, and you don't need to worry about working with an unneeded dependency. I mean I would be wasting a significant amount of time because I'm not Joe Armstrong but there are things I get asked to do that other people would use a library for and I think what, why?

3. Opacity is in the eye of the beholder. If you're working on a project only you and a few people you know can handle it will ever look at, then you are that beholder. If you're working for a big organization as a consultant and your contract runs down in a month, think of the worst guy you have ever worked with that was still a programmer - that guy is the beholder.

4. If you write a comment then they won't make the assumption.

Later: Why the downvote?

Even Later: Upvoted, so I guess someone didn't like or maybe just clicked wrong.

Re:Why I often implement things from scratch (2006) by zimpenfish on Sunday March 08, 2020 @12:20PM (#22518827)
> 1. If you were Joe Armstrong or at his level, probably not.

But 99% of us are not at his level. And more importantly, 99% of the people who come after to maintain this code are not either.

Re:Why I often implement things from scratch (2006) by bryanrasmussen on Sunday March 08, 2020 @03:29PM (#22519984)
I'm not sure if the people who come after Joe Armstrong to maintain his code are not at his level. Or at least close enough that this particular decision wouldn't be a problem
Re:Why I often implement things from scratch (2006) by henriquez on Sunday March 08, 2020 @09:55PM (#22522236)
Every time I npm install my projects and get the "you have 10 new critical vulnerabilities!" message it makes me a little more cautious about relying on third party code.

I think there's a balance between rolling your own and using a lib, and it boils down to the domain of the problem being solved. If you're really just flipping a 2x2 matrix, the linear algebra lib will have way too much junk you don't need, and learning to use it would be more work than just solving a math problem. On the other hand, if you need a lot of common functionality (like multitouch events on the frontend), then why reinvent the wheel when there are a handful of great libraries for it.

Re:Why I often implement things from scratch (2006) by smichel17 on Sunday March 08, 2020 @10:15PM (#22522328)
Hey, you're me!'I would do this:

1. Add an "invert2x2Matrix(theMatrix)" function.

2. Implement the function myself (no library).

3. Add a comment at the top of the function to the effect of "if this ever ends up doing much more than what the name says, consider replacing it with a library."

Re:Why I often implement things from scratch (2006) by ci5er on Sunday March 08, 2020 @09:03PM (#22521980)
2x2?

Do it by hand. No dense math involved. One line of code (or so, depending on coding style).

If you want to implement or call LINPACK to do a 2x2, you've got other problems.

Re:Why I often implement things from scratch (2006) by Scarblac on Monday March 09, 2020 @04:21AM (#22523830)
Do you know that we are talking about applying 1 well-known formula? And that he mentioned that the library wasn't otherwise used in the project?
Re:Why I often implement things from scratch (2006) by rubyn00bie on Sunday March 08, 2020 @05:41PM (#22520802)
> 1. Your handrolled solution is likely worse than the library anyway

I quite doubt that, though I used to feel the same.

The one feature I need in the library is probably implemented for a specific use case which is undocumented or misrepresented; and use cases outside of that are likely to be egregiously unsupported. Fixing the issues is almost always more work than just implementing X directly and looking up gotchas.

(aside: to understand this first-hand, go pick any JavaScript[0] animation library, and then go add a library that integrates it the core framework you're using (or not)... et voila, enjoy the descent into hell.)

A simple implementation of X that doesn't lock you into patterns you don't need or will one day harm you is worth its wait in gold. Seriously, I'd rather sacrifice DRY code than fuck myself eight months down the road by using a shitty over-engineered pattern that doesn't actually fit my needs.

> 2. You're wasting effort reinventing the wheel

Probably not; it turns out most of the wheel was invented and given to you in the language and runtime. For the article, it's 100% true, BEAM is pretty much an operating system and a great one at that.

We often abstract for the sake of abstraction; I honestly think Elixir/Erlang has helped break me of quite a bit of that. Rust is also nice because it'll make things so very painful for you when you abstract for no reason.

> 3. You risk adding unnecessary opacity by littering the program with dense math

Opaque libraries are the exact same thing but are even harder to understand since the source code doesn't comply with your same coding standards, methodologies, or test suite.

> 4. Other programmers will assume there is a pertinent reason you hand-rolled the algorithm instead of using the library. Now everytime someone touches that code they have to reverse engineer your approach to see what it does different from the library such that you had to roll it yourself (surprise: nothing!).

Documentation is the answer here, it doesn't have much to do with library or DIY.

Why go through the trouble to properly evaluate a solution, decide the best solution was to implement your specific use case (or otherwise), and then not document it? You're just asking to repeat yourself or forget.

On the flip-side, its really easy to assume that library authors did something brilliant when in fact they've done the opposite. Or someone will assume you've chosen this library because you took the time to properly evaluate it and never question it...

Ex.

After eight months of having the library run slow and leak memory some junior engineer pulls you aside and softly says "I have a minor in mathematics, I noticed that library Y is only doing simple matrix multiplication... I can do the same thing with this [shows you four lines of code] and its a lot faster... I just assumed we had to use that library since its in our code base."

Adding libraries before you need them causes more headaches than not because now you've littered a dependency throughout your code which may not be sufficient for future use cases. This goes back to I'd rather have less DRY code than be bound to a shitty inflexible pattern.

> The two exceptions I imagine are 1) if you really do absolutely need some slightly modified microoptimization of what the library does or 2) if you are working for a platform where there is good reason to avoid even slight bloat (embedded).

I don't totally agree with either of those statements fully but I don't strongly disagree with them either. I'd like to add for me these would be of much high significance:

1. Your future use case are unknown.

2. You do not know if the library will be maintained; so, by using it, you're going to own it anyway. There are no free lunches.

3. You're using only a small, defined subset of some standard (i.e. RFC or specification). The existing solutions provide too much cruft for your specific use case.

4. The solution is obvious and has one correct answer. In some languages this is easier because of strong conventions and standard libraries. In others, this is probably a pipe dream.

5. The libraries are not tested adequately or are not easily testable.

I dunno, over the past few years especially, I've just started doing more things myself and yeah things do take slightly longer to start (sometimes...) they almost never take more time to maintain, expand on, or use.

Each line of code used by your project is a liability (debt), not an asset, on your balance sheet... Less code, less liability, less debt.

[0] No offense to JavaScript <3, I only choose it, because it's so ubiquitous.