I have some familiarity with C++, and concepts like compiling and linking static and dynamic libraries, which is what I understand as collections of code that simplify doing certain things.

But then I get confused in certain cases, for example, why is OpenGL considered an API? Why is it necessary to use other libraries like GLAD, freeGLUT or GLFW to interface with OpenGL?

And then other languages have this thing called package managers, like pip, node, cargo, and vcpkg for c/c++, where you install these packages that get used like libraries? What’s the difference?

Finally the ones I understand the least of are frameworks. I keep hearing the concept of frameworks like Angular for js and a lot of stuff that’s too alien for me because I’m still unfamiliar with web development.

So for example, I’m using the raylib library for a small game project I have. I link the .lib or .dll file to my executable file so I know I’m unambiguously using a library. How come there’s also Cocos2dx which is a framework? What’s the distinction?

  • FizzyOrange@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    6 days ago

    It’s not hard and fast but:

    • API is the actual interface for the functions, not the implementation. It’s possible for one API to be implemented by more than one library.
    • Library is a bunch of code provided together. It might have more specific meaning depending on the language.
    • A package is something you can install. It’s pretty much synonymous to library since most packages contain one library.
    • A framework is just a library that dictates a lot about how your app works.

    Apart from API they don’t really have strict definitions so they’ll be used interchangeably and differently depending on the language.

  • pixxelkick@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    6 days ago

    API is just the term for “the surface of something that’s been exposed to you to interact with”

    Libraries, websites, tools, etc all have APIs, it’s just the general term for “this thing has something we can interface with”

    A library is a bunch of code someone else wrote.

    A package is when you use a tool to bundle up a library to make it easier to distribute to other people, usually adding a version # to it, and adding it to so.e popular package manager network so millions of people can find your package easier.

    A framework is a term for a very big cohesive library, with an advanced api, that does a whole bunch of different things that all have stuff in common. Basically a firework is a huge library that provides many many different things to do that all have stuff in common.

    Game Engines for example are frameworks.

    A library of tools to make a bunch of different website components that all work well together and have stuff in common is a framework.

    Etc etc. It’s a bunch of code that doesn’t do anything in it’s own, but provides a bunch of modular pieces you can assemble into something.

    Think of a framework like buying a big box of lego. It’s not anything specific yet, but you can assemble all those pieces together to make infinite different things.

    • Scrath@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      1
      ·
      6 days ago

      I think the best explanation as to the difference between a library and a framework that I’ve heard so far is this:

      A library is something you use to do a specific thing in your project. A framework is something you build your entire project around.

      • Gremour@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        6 days ago

        I would describe a framework as something that you embed your logic into, letting it orchestrate the flow for you. You can use several frameworks in one project.

  • MagicShel@lemmy.zip
    link
    fedilink
    English
    arrow-up
    0
    arrow-down
    1
    ·
    edit-2
    6 days ago

    An API is just a standard for using a thing. Normally, it’s part of a library. So you install an email library and there is an API for sending emails. But an API can be a standalone thing. There can be a standard for something, such as ORM (or apparently video drivers—not my area) but then there are libraries that implement the API differently. For example, Hibernate implements the JPA API. Now the individual libraries probably do have their own custom API, but if you want to be implementation-agnostic in your code you just code to the API and you can theoretically swap out implementations.

    Package as in package manager is about having a library that you need to use, which is built on other libraries, without you having to manage all of those dependencies yourself. You tell the package manager what you want and it handles the rest.

    Frameworks are built on top of the core language and perhaps a bunch of different components that all work together to create a purpose-build set of features that all work together. It transforms the language, at least within that specific domain. So for example, Spring by itself basically manages dependency injection and beans. But there are a bunch of things that can plug into that to add things like security or database access or web-session management so that you can do those things in a way that is compatible with what you’ve already learned.

    I can’t really speak to the specific domain you are looking at because I do web services, but conceptually that should all translate fairly well.


    I asked ChatGPT to see if it could improve my answer. It basically patted me on the head and ignored everything I said in favor of the following. To be fair, it at least addresses the specific domain you are looking at.

    An API (Application Programming Interface) is a specification that defines how software components interact. It is often part of a library, but it can also stand alone as a standard that multiple libraries implement. For example, OpenGL is an API that defines a standard interface for rendering graphics, but different implementations (e.g., Mesa, Nvidia’s drivers) follow that API. Libraries like GLAD, GLFW, and freeGLUT exist to help developers interface with OpenGL more easily.

    A library is a collection of prewritten code that provides specific functionality, which you integrate into your program. In C++, you link against .lib or .dll files, as you do with Raylib for game development.

    A package refers to a unit of distribution for code, usually managed by a package manager (e.g., pip for Python, cargo for Rust, vcpkg for C++). Packages often include libraries and their dependencies, making installation and dependency management easier.

    A framework is a more comprehensive structure that dictates how a program should be organized. It typically provides inversion of control, meaning your code fits into the framework’s lifecycle rather than calling functions from a library freely. For instance, Cocos2d-x (a game framework) provides not just rendering but also an entire architecture for handling game logic, assets, and input—unlike Raylib, which is just a graphics library.