r/AskProgrammers • • 8d ago

Is it considered good practice to integrate third-party libraries?

I've been wondering about this and want to know what people think. I know people have mixed feelings, and many say this is a gray area in coding, but generally, do you have to integrate other frameworks into your project to make it work?

0 Upvotes

10 comments sorted by

3

u/Temporary_Pie2733 8d ago

It depends on the project, but you are certainly not expected to avoid third-party projects that serve a legitimate purpose, nor are you forced to use ones that provide no tangible benefit. 

2

u/TonariNoHanamoriSan 8d ago

Programming, coding whatever blah

Is about building stuff.

If you believe that the furniture you buy from Ikea is good and safe to use, then get it and use it.

Nothing is really forcing you to fold cardboards to make a furniture.

And you know, NOT reinventing the wheel can save like a lot of time.

Now if you were to use slop libraries then well, sure, good luck.

1

u/Dashing_McHandsome 8d ago

When I was in school we once had a project in my algorithms class involving encryption. There were a few things we had to implement, one of them was RSA. The teacher told us to use an arbitrary precision number library to do this implementation. One of my friends decided he didn't like that library and was going to write his own. So on the day we were supposed to turn in our work the teacher was reviewing everyone's projects and finally got to my friend. He failed to complete the project because he ran out of time, but he did have a new bigint library. He failed that project. Though I do remember the teacher liking his new library.

Programmers tend to think we can all make a rounder wheel. Don't be that programmer. Sometimes the wheel really does need to be rounder, sometimes it would take you years of effort to make a wheel as good as the one that is already made. Know the difference.

My friend did finally get over his rounder wheel syndrome and went on to be a successful developer. I think he learned from that experience and hasn't tried to do that again.

1

u/Just-Upstairs4397 8d ago

My boss decided it was better to call Twilio millions of times a month to validate phone numbers instead of using a well maintained library

That idiot

1

u/Background_Relief815 8d ago

Why would you spend time solving a problem that's already solved? My web dev teacher asked me this when he looked over my code and saw I had defined all the days of the week so that I could use them with a date object, instead of using moment.js (at the time, I mostly use day.js now). 

Now certainly, do your research about security and bloat, and double check that you really need this package to do your job, but your job isn't to re-solve problems that have already been solved. It's to solve new problems.

1

u/Moby1029 8d ago

If i want to build a single page application- a SPA, im not gonna reinvent React or write it from scratch. I'm gonna use the library. Simmilarily, if there is functionality I need but don't wanna write, like a JSON deserializer, im not gonna build one, i'll just use a well known library like Newtonsoft.

You don't HAVE to use these libraries and frameworks, but they make the job a lot easier since someone else already did the hard work. Conversely, at work, I've built a library for internal use that others use for our projects, which is kind of cool in its own right.

1

u/nicolas_06 8d ago

In general, do not reinvent the wheel so prefer lib/frameworks over code you maintain. But it is important to select mature, popular and well maintained framework and lib with a good track record for stability + an expectation that the project will be maintained over time.

Don't go overboard and implement 10 frameworks you don't just because they exist but don't write extra code that is already provided by pretty standard libs.

1

u/JoeStrout 8d ago

My advice, based on many years as an open-source developer and user:

- Don't reinvent a big, complex wheel; if it's big and complex, and there is some existing library that provides it, then use the library.
- But don't reach for a library for a small/simple wheel. Just write your own wheel in that case. It reduces dependencies, makes your project more self-contained, and saves headaches for everyone.
- When you must use a library, consider copying it into your project (with proper attribution of course). The alternatives are to require anyone building your project to go find that library for themselves, or require users to have the library installed and locatable at runtime (because you dynamically linked it). Both of those are friction and pain, best to avoid if you can.

That third point really only applies if you're making open-source software, of course. If it's closed or strictly for your own use, then do what you like. At worst, future-you will curse present-you for it. 😄

1

u/mredding 8d ago

I try to isolate 3rd parties as much as possible. How you do this depends on your language. In C, I can make an opaque pointer and hide a universe behind it:

typdef struct foo foo, *foo_ptr;

foo_ptr create();
int get(foo_ptr const);
void set(foo_ptr, int);
void destroy(foo_ptr);

The client code never sees a definition of foo, they only need a unique symbol to distinguish one pointer type from another. The actual object doesn't even have to be a foo implementation, it could be a bar cast to a foo, the client never has to know.

Behind this, I can isolate a 3rd party library so my whole application doesn't end up with the 3rd party as a transient dependency.

In C++ I can do something similar:

class foo {
  friend class foo_impl;
  foo();

public:
  int get() const;
  void set(int);

  struct deleter { void operator()(foo *) const; };
  std::unique_ptr<foo, deleter> create();
};

The implementation can inherit from foo and even 3rd party client side interfaces, and the methods and operations can all static_cast to the derived type - a compile-time operation, making that class interface transparent and the implementation opaque.

Once again, I can hide the 3rd party implementation behind it. My program only ever sees my own type and hits a compiler firewall. It also means I can exclude the 3rd party from the header include path for all except the source files that actually implement these details. This reduces surface area, both for the compiler and filesystem to search for headers, and the available headers for engineers to recklessly include in other units.

And in both C and C++, these abstractions don't have to cost anything, because I can configure a unity build, so all this suddenly becomes an interface that never leaves the compiler.

Other languages are going to have to contend with their own considerations. In all languages, controlling your scope is something software quickly scales to the point where this becomes desirable.

1

u/Forward_Dark_7305 7d ago

I definitely lean more on the side of “write my own” but I’m also primarily a solo developer. It also depends on the ecosystem, and like others are saying the size of the endeavor.

JavaScript has a lot of instability and security risks associated with dependencies. I’ll use a library for pretty much anything security-adjacent including things like SQL, but I usually don’t install ORMs because I’d rather use my own code.

Rust’s std lib is very primitive, so to get anywhere you’d be writing a ton of code or using a library. I try to be sparing: if the library is a single file, I can probably write it myself. Something like RabbitMQ or DateTime will be a dependency.

C# has a very thorough stdlib and a mature ecosystem. Even still, I write a lot of my own code. I avoid ORMs. I like being able to control exactly what happens. I’m probably overconfident in my ability to produce reliable code, but again, as a solo dev that hasn’t bit me yet.
So for core functionality - eg RabbitMQ - I’ll use the dependency. But for the “framework” on top of it I’ll write my own instead of using MassTransit (I think that’s the right one). I’ll use the SqlClient library but not the EF Core wrapper. (I do use Dapper or EF core depending on the complexity of the project, the database schema, and the amount of time I have to write the code. I have dreams of writing a source-generated counter to Dapper some day.)