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?

  • @[email protected]
    link
    fedilink
    English
    2
    edit-2
    3 hours ago

    An API is a interface / contract to do something. In the case of hardware APIs, at a certain point your code actually has to tell physical chips and wires what to do. How you do that, is often a convoluted process of putting bits of memory into specific buffers, executing instructions, and moving the results around, all in assembly language.

    Those instructions will also be different, for every piece of hardware that has different buffers and instructions and features.

    From the perspective of an application developer though, you typically don’t actually care about any of that. Your application just requires something like drawing pixels on a screen. So instead of you having to detect what graphics card is there, and have to switch how your application code draws stuff depending on what card is installed, OS makers like Microsoft looked at the various hardware APIs, created a software abstraction that could work for any of them, and then published that as a unified API at the OS level that you could use to draw stuff on screen (DirectX). Application developers could just target DirectX, and then hardware developers just had to write little bits of code to run DirectX on their cards (this is what drivers are).

    OpenGL is just taking that concept one step further and agreeing on an international / open source standard for that interface, rather than one that Microsoft controls and only works on Windows.

    A library is one collection of code, it could just be a a function that returns something, or it could interact with the OS / hardware in some way.

    A package can be a collection of libraries, or it can just be one, but packages are designed to support dependencies. i.e. a package will typically be a new library that builds functionality on top of an existing one, and this has a dependency on it (and on a specific version).

    A package might also include compiled code, so it could be say, a JavaScript library that creates a JavaScript interface that is calling a compiled C++ binary, allowing you to now call C++ or assembly code from a higher level language.

    Package managers handle managing packages for you, and managing their dependencies. If you install one package via a package manager, the package manager will also install all its dependent packages for you, and will clean up dependencies when you remove it, and upgrade them when you upgrade it.

    Note that all of the above is extremely unopinionated and generic. It’s basically all just code that could do anything you want.

    The distinction with framework, is that a framework should be a full skeleton for producing something. It will typically provide libraries or packages, along with dev utilities, build utilities, testing utilities, and provide a full end to end example of how to build a type of application.

    So for instance React itself, is just a library / package. It only handles updating the React tree. It doesn’t even handle rendering anything to the screen (that’s React-DOM for web project but something else for React Native projects), it doesn’t come with a way of writing test code, it doesn’t even come with real build utilities.

    But you can build a framework around React, that’s what Vercel has done with Next.js, where they include the React library / package in their Next.js framework, and provide a whole slew of additional functionality to build a full end to end web application.

    Angular is similar in that it’s published as a full framework, as opposed to just a part of it. Spring, Django, etc. are similarly full frameworks for building backend server applications.

    Frameworks as a concept is looser too. Some of these frameworks are like game engines where you download an exe file and everything happens within that application. Sometimes frameworks are literally just a written list of instructions on how to build something. And frameworks are often built around other frameworks. For instance, Spring provides a generic framework for building a backend API, and a company’s dev ops team might build their own framework around Spring that customizes it further for their company and infrastructure.