What is a library?

If I understand this correctly, a library in computing is just a bunch of pre-written code which is meant to make working with specific tasks easier. For example, if you wanted to make a game, you would use a graphics library. But if that's the case, could you hypothetically make those graphics without using a graphics library at all? How would you do it, and would it require learning new things about the language that you're using?

Attached: 1483448309989.jpg (3840x2400, 1.81M)

>can you code graphics without a library
how were those libraries made

idk dude check the code of a Foss graphics library or engine

>How would you do it
you would need to write code that your specific GPU can read to produce graphics. the reasons why people use libraries is so that they can support all of the gpus that the library supports, instead of writing different code for each gpu

>But if that's the case, could you hypothetically make those graphics without using a graphics library at all?
Obviously.
>would it require learning new things about the language that you're using?
Yes.

>how would you do it?
Like any code. Graphics libraries are a bit special because they interact with a driver. But if you consider your graphics library to be more high level it could be something that goes on top of Opengl/directx/vulkan. Then it's just like any library you can imagine. You write a piece of code that maybe draws a rectangle, slap it into a function, now the library user can use the interface the library provides to draw the rectangle.

It's exactly like that all over the place. Imagine you use a library that opens and edits word files. Word files are mostly just XML in a zip archive. So in effect it unzips, parses XML and then provides you more convenient ability to change that XML.

Going back to the drivers from before is still very similar it's just that the library developer is working with the driver which is essentially like its own library. It has its own interface you interact with.

How long would it take to learn a language like Python completely that you could theoretically do anything with it without using a library? Or even make your own libraries?

approximately 20 000 hours

OpenGL is technically a library, but if you want to use the GPU without OpenGL then you'd have to write your own interface to the GPU driver and I've never heard of anyone managing to do that.

why do you want to avoid libraries so much? they usually have the best implementations known to man, which you will not be able to recreate with a high level language like python

you're not understanding this correctly. to clear up your confusion, let me propose a question to you:
how many hours would you have to study pigments before you could be the next van gough?

Take a project you've done and make it in C instead, you'll soon learn how much shit you get for free

I find it odd that you mention "make your own libraries" as if it's the ultimate accomplishment in the programming world.
You can make your own library in 30 seconds. Type this into a text file:
def print_with_indentation(s):
print(" " + s)

Save that file as "indentlib-v0.1.py". Congratulations. You've created a library.

I HATE LIBRARIES

I don't want to avoid libraries; I'm just interested how programming works at a fundamental level

think of libraries as separate files that have functions written in them. when you import a package in python, you're just loading in another file that has a function written in it that you can use in your own code. you can, of course, just copy paste that same function if you dont want to be importing libraries

>could you hypothetically make those graphics without using a graphics library at all?
yes
>How would you do it,
you would have to look at the driver bindings for a specific graphics card and start from there
>would it require learning new things about the language that you're using?
yes
it takes a huge amount of time to draw graphics from scratch, so don't expect to make anything beyond simple rendered gifs if you avoid libraries

you're asking a good question - essentially, I get the feeling that you're frustrated with the fact that libraries "make it too easy", and prevent you from understanding what's happening at a lower level. that is a very good instinct to have; at the same time there's nothing wrong with using libraries.
to answer your question (which I assume is, "are the libraries using magic that I don't have access to?", the answer is typically "no".
libraries are usually just code written in the same language you're writing, with the major exception being bindings to system functionality implemented in a lower-level language. as for the "magic" functionality they sometimes perform - say, writing a string to the console, or issuing commands to a GPU - the ultimate answer to "how would I perform this without a library?" often comes down to system calls (interrupt instructions) that invoke the OS to interact with peripherals or the external world on your program's behalf.

a 3d software rasterizer is a very feasible project. to implement it truly without libraries, I suppose you'd have to write directly to the framebuffer, and therefore be running with substantially elevated permissions, but it probably wouldn't take more than a few days; and afterwards you could say, "yes, I implemented a 3d environment without libraries", so long as you don't consider the BIOS, CPU microcode, kernel [etc] to be libraries.

There are open source drivers.

Is this real, anons? Is this how motherboards are made?

Libraries are a collaborative tool. Imagine you had a friend you're working with. He's written some code in the same file you're working in, say in a function. You wouldn't be surprised to find that it's easy to call his function. It's what you've been doing all along.
Libraries are just a way of doing that same thing but with various features to make this sharing easier.

Best way to learn this is to look up how you'd make your own library anyone on the internet can use for your programming language. How to get a package into pypi/pip for instance if you're using python. It doesn't have to be important or good, just try it.