do libraries save space ?

Ok this is a real noob question but I'm new to most of this so please bear with me.

Firstly, are libraries basically like functions that are just imported into your sketch?

Secondly, if you import a library that performs a complex task do you save sketch memory space? For example, say now you wrote a function that requires 1000bytes of code, and you can import a library that performs the same task as what your function will. If you look at the two options, the one with the written function will have a sketch that contains more text in it and thus it will take up more space? Compared to the option with the imported library which contains much less text, but the question I'm asking is, does the second option use less sketch space memory?

calvingloster:
Ok this is a real noob question but I'm new to most of this so please bear with me.

Firstly, are libraries basically like functions that are just imported into your sketch?

sort of; mostly a lib consists of a Class, a definition of an object with all its behaviour and state.

Secondly, if you import a library that performs a complex task do you save sketch memory space? For example, say now you wrote a function that requires 1000bytes of code, and you can import a library that performs the same task as what your function will. If you look at the two options, the one with the written function will have a sketch that contains more text in it and thus it will take up more space? Compared to the option with the imported library which contains much less text, but the question I'm asking is, does the second option use less sketch space memory?

If the function in the lib has the same code it's footprint is equal in size.

The gain is really when you have a Class with e.g. 10 bytes to describe its state and 200 bytes for its behavior (functions),
If that Class is reused for 10 objects, the code part is reused and only the state (10 bytes) is copied 10 times.
save a lot of memory.

That said, often a library has generic functions that you do not use in your sketch. These may increase the size of your sketch, so if you are out of RAM you might try strip a lib.

Thank you for the clear and simple explanation. The reason why I asked is because I recently started using shift registers and I felt like using the libraries are cheating in a way cause you don't know exactly what the program is doing.

So I don't know if this is a wrong approach in programming but is it not better to not use libraries and write your own functions? Obviously this is reinventing the wheel but what are u learning when you just blindly use libraries that you yourself have not written?

is it not better to not use libraries and write your own functions?

It depends. Sometimes you may want to get into the nitty gritty of the hardware you're using and control it all yourself, just because you can or perhaps the library doesn't do what you need. On the other hand, you may just want to get the time from your RTC so that you can concentrate on building the rest of your aquarium controller and a library lets you do just that.

Either is fine, but generally, a library is likely to have gone through a lot more testing (by multiple users) than you're going to do with your code. That testing is worth a lot - think carefully before you give it up.

Yes that makes sense but I just feel like I'm new to programing and I gota start at the bottom and work hard to learn a lot. I do use libraries though but just feel like if I use them all the time I'll never learn.

Coding is hard; you will have plenty of opportunities to learn with the code you write, whether you use the existing libraries or go the hair shirt route. Personally, I'd rather use tools already built and get my projects done but I can quite see your point.

A car analogy: when you first learn to drive, you accept that the car's systems do what you need and don't much care about the details of how they do it. It's only when you have more experience with them that you may become more picky about what's happening under the hood and wish to change out the rubber, upgrade the shocks, add that performance air filter.

So with the libraries - rejoice that they're available for now and be prepared to change or completely replace them when it makes sense to do so.

As a Slackware user, I am definitely a slacker... that being said, there is no need to re-create the wheel. Re-writing a library for slackware, so I can use a particular package, is just a waste of time, since it is already there. Not to say that you cannot do that, and you will learn a lot more...Had I re-wrote every required library, for the packages I used, I most likely wouldn't have had any programming questions, but I would still be working on installing the package. Looking at the libraries themselves, can and will teach you something about the code, so there is value there. Just my two bits.

I felt like using the libraries are cheating in a way cause you don't know exactly what the program is doing

It's not cheating; it's like an open-book exam because you can go off and read the source of the library.

They may or may not save space, but they certainly save time and get your projects up and running faster.

As long as the person who wrote the library knew what he/she was doing ...